When to Stop — A Game Over Screen

Jack Leavey
3 min readJun 3, 2022
Aliens (1986)

Currently when the player dies, the game just keeps running with no new input possible. Setting up a game over screen will add some clarity to the experience.

So first off, when should the Game Over sequence happen?

When lives hits 0 and the player is destroyed!

We can create a new UI text object (see previous articles for more UI information) to pop up when the player dies.

Straight to the point.

In the UI manager script we need to set this new text object as a variable and then have a function that can activate it when the player dies.

I also created a restart UI element that we will add function to momentarily.

Inside the UI manager C# script.

Now, a new function to turn on these UI elements.

Inside the UI manager C# script.

Notice the coroutine at the bottom?

I created a coroutine with a while loop to simulate the old arcade “Game Over” screen flashing!

This coroutine will help create the “retro” vibe of the old 2D games.

Great, now we still need to actually call the GameOver function on the UI manager. We can do that from the PlayerController C# script!

Inside the PlayerController C# script.

Now one final piece of logic to add to the UI manager C# script; the ability to reload the level ONLY after we have died.

Make sure to place this function inside of Update or it will never run!

Lastly, the scene needs to be added to Unity’s build options to be loaded correctly.

Open up the build options and press the “Add Open Scenes” button!

Let’s see it in action!

The game over screen and restart functioning!

--

--

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!