Game Over Man! Game Over!

Bill Paxton in Aliens!

Objective: Since we’ve introduced the concept of lives to our game its time to display the appropriate message when our player dies. Nothing too complicated here so let’s dig in.

Implementation: First we’ll add a new Text component that is a child of the Canvas called Game_Over_Text. Then we change the size and color to your choosing. and Importantly make the Text display GAME OVER.

In the UIManager script we create a new text variable called _gameOverText; make it a SerializeField.

Let’s save our script and pop over to Unity. Drag our new Game_Over_text into the empty slot in our UIManager script.

In our Start Method let’s make sure that when we star the game the GameOver text is turned off by adding this line.

And since its now turned off we need to find the best place for us to turn it on. That would be in our UpdateLives() method (which I may not have documented…sorry ;)

That did it! I also added a classic flicker effect by using our old friend a coroutine. Looks pretty great! In the next article I’ll go over how to restart the scene/game after we’ve gotten this screen.

Unity Developer — Technology Leader — Making Unity Game Development Look Easy