Visually Representing Immunity, the Classical Way

Console messages are well and good for us, as developers, testing and monitoring our systems, but they do nothing for players. We need something to visually represent the temporary immunity for all to see.

In classic sprite-based games, such conditions are often conveyed by causing the sprite to flicker for a few moments. As this is such a recognizable visual cue, let’s do the same. We’ll be making some further changes to the PlayerStats script, as seen in Listing 9.8.

Listing 9.8 Further Expanding the PlayerStats Script

private float flickerDuration = 0.1f;private float flickerTime = 0f;private SpriteRenderer spriteRenderer;void Start(){  spriteRenderer = this.gameObject.GetComponent<SpriteRenderer>(); ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.