Creating a Retro Game Over Behaviour in Unity

Chris Hilton
3 min readJul 7, 2021

Objective: To replicate a flashing Game Over screen behaviour in Unity just like the old retro games!

Now that we have a functioning score system along with our cool dynamic lives display, it is time to add the next feature which is going to be a retro Game Over flashing text using coroutines!

Let’s start off by right clicking on the Canvas in the Hierarchy and creating a new Text, Canvas → UI → Text and like usual this should be a child of the parent automatically:

I am going to leave it anchored to the middle of the screen and make the following changes:

PosY = 100
Text Box = “GAME OVER”
Font Style = Bold
Font Size = 150
Alignment = Centre and Centre
Horizontal Overflow = Overflow
Vertical Overflow = Overflow
Color = White;

Your Game Over text should now be sitting in the middle of screen slightly higher on the Y axis as show below:

From here we need to decide which is the best script to be setting this up in and after some trial and error, the UIManager works great as I was having many issues in the Player script due to the player game object being destroyed in the same frame that I was starting the coroutine, meaning that the ‘Player’ script was getting destroyed at the same time the player died and I was losing all functionality! Problem solved…phew!! Time for some coffee…

So within the UIManager let’s add the following code and run through it all:

Firstly, we need to create a reference to the GameOver game object we have created in the Hierarchy and don’t forget to assign this in the Inspector.

Next, check our currentLives and see if the player has died (or their lives are less than 1) and if this is true, start the GameOverFlicker() coroutine.

Lastly, within our coroutine, make sure it is within a while loop so it continues indefinitely until you restart the game. Then, we are going to switch our GameOver game object ‘ON’ and then wait 0.5 seconds and switch it ‘OFF’ and then wait for 0.5 more seconds and back to ‘ON’, continuing in a loop!

Alternative Method:

As we created a GameOver Text, we can create the same result a slightly different way. Instead of creating a GameObject to reference, we can create a Text:

It should already been assigned in the Inspector, but double check to make sure.

And then within the coroutine, we need to set the ‘gameOver.gameObject’ to ‘true’ and ‘false’. Compared to the original code, we simply needed to add ‘.gameObject’ to get a reference to the game object, where as in the original code we had created a GameObject type already.

Same result in the end! The game is starting to take shape.

Next up: Let’s give the player an opportunity to restart the game when the Game Over flicker starts!

--

--