Day 24: Creating a Retro Game Over Behavior
Objective: Create a Retro Game Over
Start off we will need a Game over text. Right click on Canvas go to UI and Text. Name it Game Over.
Size it to the size you would like and change the color to White. In the Text block, remove New Text and put Game Over.
If the size is to big and the text disappears, you can click on horizontal and vertical overflow and allow the text to over flow the rect area.
To get the Game over to appear when the player dies, we will move to the UIManager. We need to get a reference to the Text object, function to enable it, and to make sure it’s disabled when the game starts.
In the start function we’ll set the game object of this text object to disabled. This is just to make sure we don’t see it when the game starts.
We’ll make a function to enable the object when the player dies.
Now to get the game to call this function, we will move to the player script and when when check to see if lives is less than one, we’ll add this there.
This is how you get the Game over to appear when you die. To make it more fancy, we’ll add some flickering. Back in the UIManager, we’ll create a Coroutine and put the code in a infinite loop. In the loop we’ll wait .5f seconds disable the object, wait another .5f seconds and re-enable the object. I created a global variable to adjust the flicker in Unity.
Make sure you start the coroutine in the game over function. Now you have a fancy game over!