2D Galaxy Shooter — Invulnerability after Damage

Marcus Cohee
Sep 5, 2021

Hello all!

Today, I will go over how to make the Player invulnerable after getting damaged! It makes the Player blink like retro games too!

Damage Behavior

Everything is in the Player script and dealing with the Damage() method.

  1. Open the Player script.
  2. Head down below the Damage() method.
  3. Make an “IEnumerator InvulnerabilityRoutine()” method:

4. Then start the coroutine right below where “_lives — “ is.

So whenever you get damaged, you can’t be hit for 1 second. This also makes it where you can’t pick up Powerups, so be careful!

That was how to make your Player invulnerable after getting damaged! Easy enough, right!? Next, I will make a new kind of Enemy that comes in from the side and goes down at an angle!

Thank you for your time!

--

--

Marcus Cohee

I am starting Unity and learning the ropes as I go! Let’s take this journey together!