Unity3D: Creating a Retro Game-Over Behavior

Would you like to create a simple Retro Game Over behavior like an arcade game in Unity? I’ve got you covered!

The behavior we want is to have a Game Over UI element flicker when the player dies. It requires setting up the UI element in Unity and create logic through code for it to flicker.

First, let us create a new UI element of “text.”

This will create a Canvas and an EventSystem. Make sure to name the Text to Identify what it will display.

We also want to make sure that our Canvas has its Canvas Scaler set to “Scale With Screen Size.”

Select the Text we’ve created. Set the anchor to the center so that it scales from the center. Type in “Game Over” so that we can adjust the object in the Scene view. Change the font size to “50”. Make sure the Vertical Overflow is set to “Overflow.” Change the color of the text white (or preferred color of chouse). Follow along with the example down below:

We now need to adjust out text in the Scene view.

In the Scene view, select “2D” in the upper left corner. This will allow us to adjust UI elements with ease.

We can now drag our text element to the center of the white box. The white box is a representation of the game’s dimension. It also represents where the UI will be displayed on the screen.

Now that we have our text UI set, we can disable the game object so that it can be enabled through code when the player dies.

We’ll create a UIManager script and attach it to our Canvas game object. Open the script with an IDE.

We need to grab a reference of the text UI element we created earlier. So we’ll initialize and declare a variable of type Text. It is part of Unity’s UI library so we need to add the namespace using UnityEngine.UI;

The text variable we created is:

[SerializeField] private Text _gameOverText = null;

Let’s go back to Unity and reference our text to the variable we created in the inspector.

We then need to create a coroutine for the flicker.

While true, which will run forever after the player is destroyed, we grab the text and change the string to “Game Over.”

We then wait for half a second before it disappears.

Then we change the text to be empty by having no characters inside the quote marks.

Lastly, we need to wait for another half a second for it to reappear again.

The coroutine should be called upon the player’s death, but due to this being a tutorial, we will call the “game over” text by hitting a key.

If we press the ‘G’ key, the game object of the text will be set active. Once, active, we can start the coroutine.

This is a short gif displaying what we have created!

You can go all-out crazy by customizing it further. You can add a game-over image instead. You can use Text Mesh Pro, which has more settings to make beautiful and richer text.

You can obviously create a polished game-over display like any other game through the use of Unity. It’s in your hands to do so!

That is all for today! Thank you for reading. :)

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store