Creating a Retro Game Over Screen (2D Space Shooter)
Just a quick article about this arcade-style blinking effect for the Game Over/‘You Died’ display for the 2D Space Shooter project I’ve been working on. There are multiple ways we could’ve done this, for instance setting the GameObject to active or inactive, enabling or disabling the text component, or by setting the text to empty before restoring it. I’ve opted for the last of these, and am using a coroutine with a while loop and WaitForSecondsRealtime delay:
With each iteration of the loop I’m checking to see whether the TextMeshProUGUI component’s text is empty or not; then I either set the text to either an empty string or assign it the value of the private string _displayText (“YOU DIED”). I’m using a serialized private float for the delay (_flickerDelay), so I could adjust the speed of the effect at runtime until I was happy with it.
And with that, I think that’s most of what I have to say on getting this effect 😉 I’ll include a couple extra notes below:
A couple quick notes:
- This TextFlicker method, along with a few others, is called in the event the player loses their lives (specifically, the methods are listening for a ‘playerDied’ event).
- The slight glow effect on the text was achieved by adjusting the SDF material on the text itself (and adding an underlay), but it’s worth bearing in mind this’ll cause the same effect on any text which uses the same material (so I’d recommend creating a duplicate of the material and giving it a suitable name like Red_Glow).