Creating a Retro Game Over Behavior

Siddhant Thakur
Nerd For Tech
Published in
3 min readApr 19, 2021

--

In the previous article we saw how easy it was to build a UI in unity. Let's build upon it further by adding a Game Over Screen once the Player has no Lives left.

For starters let’s create a Game Over UI Text component which will be displayed when the Player has zero lives left.

This should create a Text Object within our Canvas. Edit it and place it and anchor it to your desired position.

Here, Text component has an interesting field called Horizontal/Vertical Overflow, this can be useful when your text exceeds the defined boundary which makes your text invisible.

Then we can select the Overflow option to make the text ignore the Text boundary.

With our Text UI ready for use lets have it be deactivated by default, and only active when the Player has no Lives left.

With this done let’s code our Game Over behavior, we want the Game Over text to flicker over fixed intervals of time to give it a retro game vibe, and since we’re dealing with a routine/time interval type of logic, we can use Coroutines(to learn about Coroutines click here),

Now let’s define the flicker behavior,

When the above function is executed the Game Over Text object will be toggled ON and OFF every half second. Giving us a flicker behavior.

Let’s call this function in our UpdatePlayerLives() where we keep track of the number of lives the Player has left(UpdatePlayerLives was defined in the previous article).

This gives us the following result,

Thank you for reading. More to come!!!

--

--

Siddhant Thakur
Nerd For Tech

Aspiring Game Developer with experience in the field of Machine Learning.