A Simple Retro Game Over Behavior in Unity!
One thing every game needs, and one thing many of us hate to see, is a ‘Game Over’ screen for those times when the game beats us. Today we’ll create a retro-styled ‘Game Over’ message, using what we learned in the previous article!
First, we will need a new UI ‘Text’ GameObjecct, which I will name ‘Game_Over_text.’
I have also decided to go with a different font that I have found on Unity’s asset store, and I will also be adjusting a few more parameters, such as the positioning and the scale of the text. Until I have created something like this, with which I am satisfied.
Next up, we have to create a simple behavior for this text. For that, we are going to add some more code to the ‘UIManager’ script.
The first change will be a variable, which will hold a reference to the ‘Text’ GameObject, and I will be disabling this in the ‘Start()’ method.
We can now drag the ‘Text’ GameObject directly into the variable field on the ‘UIManager’ script on the ‘Canvas’ GameObject.
Since we want our ‘Game Over’ text to be flickering on player death, we will be using a Coroutine!
There are many ways to do the flickering behavior; for example, you could turn the ‘Text’ component of the ‘Text’ GameObject on & off or set the whole GameObject active and disable it. In the end, I have chosen to change the text every half a second.
Now, we need to figure out when do we call this Coroutine - and the easiest way is when we are changing the life on our UI in the ‘UpdateLives()’ method.
Whenever the player reaches 0 lives, the ‘Game Over’ text will appear. Now all that remains is to play around with the text presentation so that you are satisfied with the result!
But that is it for now, thank you for reading and feel free to follow me for more articles - and as always, good luck and see you next time!