Creating a Retro “Game Over” Behavior.

Objective: Via the Unity UI, project a flashing “Game Over” message.

What better way to inform the player that his quest for victory has been dashed by flashing an ominous “GAME OVER” banner across the game scene! Follow along as I quickly show you how to implement this feature into your own game.

You begin by creating a private text variable in your UI Manager. In my case, I’ve opted to use Text Mesh Pro (TMP_Text) and called it _gameOverText.

Create a private variable of type Text Mesh Pro Text (TMP_Text) and set its name to _gameOverText.

Once I have the font type, size, position, color, etc…all set up to my liking, I need to turn off the text. Why? Well, if I don’t, it’ll just confuse the player :).

I do so in the void Start() method by setting the SetActive attribute of my game object (_gameOverText) to “false”. Just like that, it’s “turned off” and remains invisible even though it continues to sit on my canvas.

Change the SetActive property of your _gameOverText to false to make it invisible on your canvas.

As the player loses his life in the game, the UI Manager looks at the int value of the currentLives variable and turning on or off the appropriate sprite image corresponding to the status of his remaining lives. Once the currentLives equals zero, it executes the GameOverSequence() method.

This is where we turn back on the hidden TMP_Text fields. We start by telling our Game Manager to run its GameOver() function which basically allows us to navigate the game by looking for specific key inputs from the keyboard. We then turn on the GAME OVER text, as well as the instructions guiding our player on how to restart the game, or how to return to our main menu. The magical retro game look comes from the coroutine GameoverTextFlicker().

TMP_Text fields are all SetActive to true.

The GameOverTextFlicker() coroutine is fairly simple. “While” it is true that the game is over, let's continuously loop this coroutine, turning the _gameOverText off and on at 0.5-second intervals. This sequence will continue until the player either decides to restart the game or return to its Main Menu scene, either of which will interrupt the coroutine by setting the condition that the game is over back to false.

There you have it. A flashing, “in-your-face” game over message bound to engage the player’s competitive spirit to a rematch. Would you like to play again? ;)

Thanks for reading!

--

--

--

Military member with 34+ years of service, undertaking an apprenticeship with GameDevHQ with the objective of developing solid software engineering skills.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

3 steps for kicking your Impostor Syndrome

How Binding.Pry Became My Best Friend

Using Knative with Otomi Container Platform

How PropTech Startups Shape Future of Real Estate with Python?

Not Null — How to Avoid Null Errors in your Code

PostgreSQL and tkinter

Super easy Python stock price forecasting(using k-nearest neighbor) Machine learning

Why does Everyone Wish to Learn Java?

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
Michel Besnard

Michel Besnard

Military member with 34+ years of service, undertaking an apprenticeship with GameDevHQ with the objective of developing solid software engineering skills.

More from Medium

Adding a wave system to our prototype

Pitfalls with Unity Unit Tests and [Timeout]

Lerp Squares — Part 2

Getting Started with Unity