Retro Element: Adding a Flashing Game Over Screen (Game Dev Day 22)

Now that we know how to build UI elements, we can explore creating a Game Over screen. First, we will need a new text UI element.

We make this these same way we made it for the scoring system.

Make a new U — Text Game Object.

Let’s name this “Game_Over_Text”. Don’t forget to change the text it displays in the Inspector as well. Mine reads “GAME OVER” and I changed the text color to red.

Position this object where you want it to display on your Scene window. Mine will be centered and slightly higher than the middle of the screen.

What we want to display when the player loses all three lives.

Now we don’t want to see this object all the time, only when the player is out of lives.

First thing is to create a new variable on the Canvas game object to link this Game_Over_text to (just like the Score_text).

The new variable.

Drag it onto the component in the inspector and let’s dive into the logic needed to display this.

How does the player lose in this game? They lose their three lives. So the defining variable on whether we see the Game Over screen is based on our lives system.

So if our current lives = 0, display the Game_Over_Text.

Let’s make a coroutine inside the UI Manager called GameOverSequence to handle this game over behavior.

The coroutine for the Game Over sequence. We will be adding to it later for the Flicker effect.

Now we make a function for Update Lives in our UI Manager and use an “IF” statement.

Don’t worry about line 37, we will be adding sprites to the Lives system later.

Finally, let’s make sure that the Game Over text is automatically hidden before the game starts up. We can use a SetActive(false) command in void Start.

We can put it right underneath our Score reset code.

Now when the player runs out of lives, it should display the Game Over text.

You should see this text once out of lives.

Let’s take it a step further, and make it flicker like the old arcade games.

A flicker effect is just turning the UI element on and off on a timer. We will need to make a coroutine for this in our UI Manager.

The Coroutine for the flicker effect.

This coroutine simply inputs the logic for the Game_Over_Text object to disable and re-enable every half second.

Now we need to call the coroutine when the game over sequence happens.

Add the StartCoroutine to your GameOverSequence.

Let’s see what it looks like!

Our functioning Game Over Screen.

Unity Developer