Creating a Retro Game Over Behavior
Next up, let’s get a game over screen going for when our player dies.
First, we will create a UI text gameobject and enter GAME OVER as the text we wish it to display. We can increase the size to 50, but it won’t show up on our screen. To fix this, what we have to do is adjust the horizontal and vertical overflow:
Now we can go back into our UI script and set it up to turn on when we lose all our lives.
First, we want to create a serializefield for the text to be placed into. From there, we can set it to false at the start of the game so it isn’t on our screen. Next, we just let unity know that if currentlives == 0, then we want to turn it true so that we have it show up on our screen when we die.
Now that we have it showing up on our screen, let’s give it a more retro flashing look to it. There are a few different methods to achieving this, but for now we will just set it up as a coroutine.
Now, let’s see how it looks in our game.
And that’s it. We’ve successfully implemented a flashing game over script. Next, we will figure out how to load new scenes and create a main menu to work with.