Invincibility Script

During the development of our game, we discovered that we needed to be a bit more forgiving to the player when they take damage. Our solution to this was to give the player brief invincibility frames when they take damage.

The makeInvincible function calls a coroutine to cause the player's avatar to flash between it's default color and a red color to indicate invincibility.

To make the player invulnerable for the duration of the flashing, I changed the game layer of the player to an unused layer in the setLayerToInv() function so that the avatar appears on the screen, but the actual game object doesn't exsit in the same layer as enemies and their projectiles. After the 1.4 seconds elapse, I change the layer of the player game object back to its default with setLayerToPlayer().

Address


Ann Arbor, MI 48104
United States of America