Unity Dev Blog: Creating a Cool Game Over Screen

Michael Hatfield
2 min readApr 25, 2022

Do you ever wonder what happens when we die?

In video games, when your player dies, they can just restart and play again, right? The game would probably not be very good if that were not the case. Of course it is not very realistic, but video games are usually played for entertainment so it all works out. The keep is to keep the player invested. Die too easy and too often and the player will lose interest. Never have them lose all their lives and they eventually get tires and walk away. It is a tough balancing act.

Luckily, writing the code for a cool game over screen is not so tough. A simple text box with the “GAME OVER” text, placed in the center of the UI Canvas can be coded to appear to be animated (of course you could animate it but this cool too). Just disable the game object and reenable it when you need it.

I put this code into the UIManager script function that updates the lives-left display (oh yeah, I did that and forgot to write an article about it — got into the zone and kept going). Anyway, inside the UpdateLives() routine the code checks to see if we are our of lives. If we are out of lives, then the game over text is displayed and the game is effectively…well…over.

Now here comes the fancy part. I used a CoRoutine to loop through changing the text. Words, blank, words, blank, flicker, flicker…

Here is the code to produce the final product. There are probably hundreds of ways to do this and get exactly the same outcome, but this how I chose to do this this time.

And here is how it looks in game. Notice the lives left display in the top right corner of the user interface? (And yes I know there are no explosions yet. They are scheduled for Day 21, I promise)…

Tomorrow I will create the main menu screen and the replay button. I will be demonstrating how to load in different scenes during run time in Unity.

See you there!

--

--