Creating a Retro Game Over Behavior

The goal of the day and create the game over screen.
Let’s talk about User Interface (UI). To our game over screen, we want to give that retro blinking effect.

Unity has a whole section for what concerns the UI, basically, it allows us to create a transparent screen between the camera and the game space. On that screen, we will add our UI elements like lives, score, and our game over message.

When you want to create an element for the UI automatically is generated a Canvas that can contain it and an EventSystem.

Once we have created our Text we go to position it correctly and insert the text.

we have a series of parameters that we can modify concerning the size of the text, its color, its alignment, and many others.

Particulars to pay attention to are the parameters “Horizontal Overflow” and “Vertical Overflow” where I recommend you to set “overflow” so that the text is not sent to wrap or disappear because it does not fit in the box.

Also on the Canvas, I recommend that you change the “UI Scale Mode” field to “Scale With Screen Size” so that you don’t have any unpleasant surprises when changing the resolution of the game.

Finished the graphic implementation we move on to the code. To manage to create the flashing effect we will use a coroutine.

The management of this coroutine is done through the management of the lives of the player, or when the lives go down to is updated the UI element of lives if the lives are less than one is called a method that will activate our text, thanks to the SetActive of each game object, and will launch the coroutine that will change the content of the text every half second.

Let’s go back to Unity and assign our text to the field we have created specifically for it, remember to disable it before starting.

This should be the end result.

project manager by day, unity developer by night