Creating a Retro Game Over Behavior

Richard Morgan
Jun 16, 2021

Today we’re adding a retro game-over behavior. We want the GAME OVER text to flash on the screen.

First we add a new UI Text element to our canvas, and then we can either update the text from blank to GAME OVER, or we could just activate and deactivate the text. Let’s activate and deactivate the text element using gameObject.SetActive().

We’ll need a reference to the text element, so we serialize the variable and then drag and drop our text element onto it in the Unity UI. Now we can set the value of SetActive using {variable_name}.gameObject.Setactive() like this:

Adding a WaitForSeconds function gives us the alternating active/inactive retro-flashing effect.

--

--