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 :
Answer by tylerdtrudeau · Mar 05, 2021 at 01:57 AM
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
Answer by Patahuete · Mar 05, 2021 at 02:37 PM
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 !
Glad to hear it! One thing I will ask is that if my answer was correct, can you accept it as the correct answer. That way it will show in the help room as being solved and other people wont be co$$anonymous$$g in here to try to help you as well. Cheers
Your answer
Follow this Question
Related Questions
explosion problem in space shooter 0 Answers
Trying to add script to a GameObject...keep getting Nothing Selected Script.. 1 Answer
Help with "updating" code 1 Answer
How can I make my Raycast ignore my player, but have other player's Raycasts be able to hit it? 1 Answer
How to Ignore Collisions Between a Layer and a LayerMask? 1 Answer