Creating a retro game over screen in Unity is pretty straightforward. All that’s really needed is a few text elements.
The UI Manager script has serialized fields, that I’ve dragged the text elements into. For my game over screen, I wanted the main text to be static, with a flashing “instruction” underneath it. All other parts of the UI are hidden, except the score.
When the player dies the UI Manager is told that the game is over, and starts a coroutine that takes care of the rest 😀
Handling the player pressing the R key is handled by a different script since that technically has nothing to do with the UI.
Unity makes it easy for us to create a User-Interface (UI) for our game.
Right-clicking in the hierarchy and going into the UI section of the menu that pops up, gives you a list of various elements to use.
As you can see, most of them are pretty self-explanatory 😀
Evident by there being two different types for some elements, there’s also something called TextMeshPro.
TextMeshPro, often abbreviated to TMP, provides more advanced features. I’ll be sticking with the ‘default’ one here, though.
For my game, all I really need is some text and image displays. …
Swapping out if-else if-else with a Switch statement.
If you have an if-else statement with several different conditions to check for, it can get quite unruly, fast.
By using switch statements instead, you end up with something where it is easier to see what is happening.
Since I plan on having more than just 1 power-up, I will make it something a bit more modular.
Making it modular, means I don’t have to create a new script for each and every variant I need. Instead, I can use one script that holds enough information for it to indicate what powerup it is.
Doing it this way, I only have to change a variable and replace the sprite!
I opt to use IDs to represent the different kinds of powerups.