My 90 day journey becoming a Unity game developer: Day-24

Rhett Haynes
3 min readJun 24, 2021

Objective: Adding game over text to the game when the player loses all 3 lives. Plus, make the game over text flicker off and on.

Game Over text appears and flickers after the player’s game ends.

To start, on the Canvas game object right-click and under UI select Text to create simple text. Name Text game object to Game_Over_Text. Then change the font size to 50 or whatever size you prefer. We won’t be able to see the text because it will be too big. So change the horizontal and vertical overflow to Overflow and you should be able to see the text onscreen. Also, change the font color to white which will make the text easily visible onscreen. Inside Text area write Game Over and the words will appear onscreen. To center the text, go to Alignment and select the Center paragraph.

Game Over Text game object set-up.

Let’s go to the UIManager script and create a new serialize Text type variable name gameOverText.

Go inside the Start() function where we will set the gameOverText game object to be turned off when the game starts.

On the Canvas, drag the Game Over Text game object to the game over variable under the UI Manager script component.

Assign Game Over Text object to variable game over text.

We will go inside the UpdateLives() method and check if lives equals zero to show the game over text.

Set the game over text to true when the player has no lives.
Game Over show after player loses all its lives.

Now we will create a coroutine to control how the text will flicker and the time in-between the flickering name GameOverFlickerRoutine(). With this coroutine we want to say while this coroutine is true to show the game over onscreen, then wait a half-second before showing no text onscreen. After waiting another half-second, keep it alternating between showing and not showing the text onscreen.

Inside the UpdateLives() method, when the current lives equals zero the game over text is activated. Right after being activated we want the GameOverFlickerRoutine() to run and make the text show on and off.

Game Over Text flickering on and off.

Next time we will create a way to restart the level.

--

--