Creating a Retro Game Over Behavior
Objective: Create a UI Game Over text and show it when the player have no lives left
At this point the game has the functionality to destroy the player when it has 0 lives. Now we have to add a UI text to indicate the player that the game is over.
First we’re gonna create 2 UI text in the Scene, one for the game over text and other to indicate to the user how to reset the game. After creating the scene we have to modify the color and the position until we are happy with the result. In this case I putted both texts in the center of the screen in a white color.
By default I disabled both texts. The idea is to show the text when the player is dead.
In the UI manager we have to create 2 Text variables and assign the references in the inspector. Then we’re gonna create a coroutine to fliker the game over text to give the retro effect, is as simple as activate and deactivate the text in a fixed period of time. Last thing in the UI manager is create a public function to show the game over screen.
Now in the player script we have to call the function to show the game over text when the player dies.
And that’s it! We have a completely functional Retro Game Over Screen.