Creating a Retro Game Over Behavior

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store