Creating a Retro Game Over Behavior

Jason Schneider
3 min readJul 31, 2021

What we need to accomplish now is to have GAME OVER display on the screen when the player dies and also have it flash in an 80’s Space Invaders retro kind of way.

First things first, we need to add a Text object to our canvas and name it Game_Over_Text. Next we need to change the text to GAME OVER and adjust the size and position of it to our liking. Since the position I have chosen is fairly central I will anchor the text to the middle and center. I will also set the horizontal and vertical overflow to overflow.

Now in our UIManager script we need to add another variable as below and save the script.

Now we jump back into Unity and drag the Game_Over_Text into the newly created Game Over Text field in the inspector. Jumping back into the UIManager script we can add:

to the Start() method.

Next we need to add an if statement to our UILivesUpdate method as follows:

Then, we need to create the method GameOverSequence() as below:

Saving the script and jumping back into Unity (I will set lives to 1 in inspector) and then running game gives:

Awesome, so that part works. How can we get the text to flash? This is another opportunity for us to use Coroutines (YAY!!!). So, if we add the following to our GameOverSequence method:

Then we need to create the Coroutine as below:

Saving the script and jumping back into Unity (I still have lives set to 1 in the inspector) and then running game gives:

HOW EIGHTIES MANNN!!

--

--