Unity: Adding a retro ‘game over’ screen

Once our player has lost all their lives, we need to show them clearly that the game has ended. Here’s how to do that in a simple way.

Ian Plumpton
3 min readJun 20, 2021

So we start out by adding another Text object under our Canvas called GameOverText.

I set the font size to 60pt and adjust the bounding box to fit the text.

With the text bold and white to make it stand out better, we centre the text and move it slightly above the middle of the screen.

By default, we want this text to be off to begin with. We can disable the text element in the Inspector.

Over in the UIManager script, we add a variable for the new Text object. In Start() we double check it is disabled when the game starts, then we create a new method to enable the game over text when the player dies. We could choose to check the lives in the UpdateLives() method we created earlier, but for now I will leave it in it’s own method.

In the Player script, when lives is less than 1 we can now also call the OnPlayerDeath() method in the UIManager.

And there we go. Now when we lose all of our lives, we definitely get the message!

But I don’t think this is quite retro enough. Let’s add a flicker.

Back in the UIManager script we create a coroutine with an infinite while loop; as this is using two yield returns, it won’t crash the system.

We enable the text as before, wait for 1.5 seconds, disable the text, then wait for half a second.

Now if we start the coroutine in the OnPlayerDeath() method, rather than just enabling the text object there, we get a nice flashing GAME OVER.

--

--

Ian Plumpton

Software developer in the field of Unity and C#. Passionate about creating and always driven to develop.