Creating a Retro Game Over Behavior

Alex Tolson
3 min readMay 22, 2023

--

We’ll be creating a classic Game Over text for when the Player expends all lives.

This is a continuation of a previous tutorial.

So, what we want is a retro style Game Over text to appear after the Player loses their last life.

Retro Style Game Over Text

In order to achieve this, we’ll need a reference to the GameOver_Text gameObject.

A handle to the _gameOverText, serialized, so that we can complete the reference in the Inspector.

When the game begins, we want the Game Over text to be hidden.

Placed within the Start() function to set the Game Over Text to be hidden initially.

We need to know when the player dies. We also need to know how to communicate with the UIManager to tell it display the text. For this, we’ll use script communication.

On our Player script, we’ve already determined when the player dies, in the Damage() method.

The Damage() method where we check if Player lives is less than 1.

However, if we add logic to the Player script, when the Player gameObject gets destroyed, so will that behavior. What we need is to add logic to operate the UI… to the UI script.

Our logic is as follows:

While the _livesImg.sprite is equal to the the _livesSprites array, Element 0 (which we have designated to be “zero lives left”), activate the game over text. Wait .75 seconds. Deactivate the game over text. Wait .75 Seconds. Repeat the While loop.

Now, we’ll need to call this coroutine from the SpawnManager. We have just the spot for it. In the SpawnManager, we have a method named OnPlayerDeath(). It is here that we can call our coroutine, using StartCoroutine.

Let’s test our game.

We’ve achieved that Retro Game flicker!!!

This concludes the tutorial on Creating a Retro Game Over Behavior.

Thanks for stopping by.

--

--