In my code whenever I click a prefab is instantiated (shooting). But i want a cool down town timer so i added the WaitForSeconds method but its not working. What is the problem. Here is my code:
Coroutines are not used for that, they don’t prevent a piece of code from being called, you’re starting a new Shoot coroutine on every Update where the condition is true (the mouse button being down).
A coroutine is just a method like every other, but it can stop at some point and continue from there later. In your case your coroutine is instantiating the laser, then stops for 5 seconds and then it finishes.
I’d do it without a coroutine, just store the time of the previous shoot and check if it passed enough time in the if condition. Something like this:
have you tried adding a boolean to activate and deactivate the cooldown either end of the IEnumeration to prevent it being called again? just adding a WaitForSeconds will not prevent the Coroutine from being called again…