Playing with UI — Game Over Flicker

Objective: Implement a vintage Game Over flicker appearing on player death

This is going to be a super quick tutorial, effectively showing how easy it is to get some good working UI stuff with Unity.

First let’s create another UI text object and name it GameOver, anchor to the centre and adjust size and position so the text (Game Over) will be properly centred. Once it is done, disable the text component using the tick box.

The reason why is to start with a disabled text, so it will not appear, and then enable it when necessary.

All is set up, we just have to code the behaviour.

In UIManager script, let’s grab the gameover text by finding it among canvas children and disable it at start. The let’s write a coroutine for our flicking text.

The coroutine is simply an infinite loop in which we will enable the text, wait, disable the text, wait and start again. In the future the loop will not be infinite and will have a proper exit condition.

But when do we have to start the game over coroutine? Obviously when the player dies! … and it dies when the lives go below 0. We already have a method here that checks it, let’s just change it a bit.

So, we are now checking if the lives become negative and, in that case, we disable the sprite and start the coroutine. Here is the result.

--

--

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
Daniele Quero, PhD

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams