Creating a Retro Game Over Behavior
No More Lives
3 min readMay 24, 2022
Well, all my lives have been destroyed by the enemy. GAME OVER!
- To implement the GAME OVER Behavior, I first added another Text object to my Canvas and named it “Game_Over_Text”.
- I changed the actual text to “GAME OVER!”.
- I increased the Font Size to “50”, changed both Horizontal Overflow and Vertical Overflow to “Overflow”, and changed the Text Color to white.
- After centering the “GAME OVER!” text in the scene and unchecking it in the Inspector panel to hide it from the scene, I headed over to the UIManager script to add some code.
- I created a variable named “_gameOverText” and added the [SerializeField] attribute in order to set it in the Inspector panel.
- I dragged the “Game_Over_Text” object from the Hierarchy into the corresponding slot in the Inspector panel.
- Back in the “UIManager” script, I added some more code to ensure the “GAME OVER!” text was not active at the start of the game.
- I then had to add code in the “UpdateLives(int currentLives)” method inside the “UIManager” script, to let Unity know when to turn on the “GAME OVER!” text.
What game over sequence is complete without the ‘Retro’ text flicker effect?
- I headed back into the “UIManager” script and added a coroutine named “GameOverFlickerRoutine()”. Then I added a call on that coroutine inside the “currentLives” ‘if’ statement within the UpdateLives (int currentLives) method.
The following effect is exactly what I wanted: