Creating a Game Over overlay

Frank Warman
3 min readApr 27, 2021

We got our Player’s lives displaying properly, but what happens when their Lives reach 0? At the moment, nothing. The Player gets destroyed and that’s it. It’s time to spruce it up a bit and really let the Player know that they are indeed, 100%, without a doubt, dead.

Retro arcade Game Over.

Creating the Text

Just like with our Score, we’ll simply be using Text as our UI element.

Create the Text element, change the Text and colour:

Creating our Game Over Text

Then we can change the font, font size, and change our Horizontal and Vertical Overflows to overflow. This allows our text to bleed through it’s Rect Transform. Then we can position our Game Over text to the center of the screen!

Modifying the text further

The UIManager script

We’ve got the Text element ready to go, now to make it do some stuff! In our UIManager script we’ll first create a reference to our Game Over Text:

_gameOverText handle/reference

Also we’ll create a new function to activate our Game Over text:

It’s important to note that we need to access the .gameObject of our text element to access the .SetActive() function!

Then we can properly link our GameOver_text in the Inspector:

Link that text!

And since we don’t want our Game Over text to be active when we start the game, we’ll deactivate the GameOver_text Game Object:

Deactivating the Game Object

Now we’ll update our UpdateLives() function to activate our GameOverScreen() when our Player’s lives = 0:

When current lives = 0, turn on the Game Over Screen!

Our code in action:

Example time!

Creating a Flicker Effect

While it’s great that we have a working Game Over screen, it doesn’t quite feel right, yet. I would like it to flicker and really grab the Player’s attention, like a retro arcade game.

To achieve this effect, we can use our good friend Coroutine to turn on/off the Game Over screen to look like a flicker. This will change the code of our GameOverScreen() function, but that’s okay!

Fancy new Coroutine.

This will turn the Game Over overlay on and off every 0.5 seconds :)

In action!

Great success! Our Player now knows when he has completely and utterly been destroyed! But now we’re stuck on this screen forever… That’s not good.

Next we’ll look at Scene Management and reloading the scene/game.

--

--

Frank Warman

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles