Invincibility mode does not change after the timer finishes

Hello everyone !

I’m working on a small vertical space shooter (my 2nd project so far) and I followed some tutorials about creating invicibility frames after getting hit. The thing is that, even after using different techniques, from different videos, my Player gameObject, which switches to a “Invicibility” layer while the invicibility timer is on, does not return to its base layer after…
I can’t wrap my head around that problem, I really think I’m missing something but I don’t know what…

Here’s a screenshot of my code :

I think what is happening is that you are calling the coroutine in your enemy script. So the coroutine starts and makes your player invulnerable. then while its waiting for the timer, the other method is still running so calls Destroy on itself. then its destroyed and so is the coroutine before it has time to revert the layer back to original state. what i would do is run the coroutine on your player script and you can just call it from the enemy script to start it. Then it wont matter once the enemy destroys itself because the coroutine is still running on the player.


Let me know if that works

I did move the coroutine to my playerController script, and it did work !
Thanks, I really wouldn’t have think about it all by myself !