So in order to use 'yield return new WaitForSeconds();' I needed to return IEnumerator for my PlayerFire(); method in order to not get compiler errors. However, now that I can play the game, the method doesn't seem to do anything though it is still being called. I'm not clear on why this is and any explanation or a better way to do this without using WaitForSeconds function would be helpful.
asked Jan 07 '12 at 12:41 AM
Coroutines are not normal functions. They are so called generator--functions which "generates" or create a special object which is returned by the function. This object can be used to iterate through your coroutine, in other words: to execute it. This iteration is done by Unity's coroutine scheduler, but you have to "hand over" the generated object to Unity. This is done by calling StartCoroutine() with the generated object as parameter.
So far, that's how coroutines work. In your case however it makes no sense. You have a firerate of 4 shots / sec. The coroutine would wait 5 seconds (if powerup == 1 or 2) before even shoot. You will have 5*4 == 20 coroutines running at the same time. Your powerup timeout check should be done elsewhere.
Those two lines looks like debugging code:
It's better to use a function or property to set / activate a powerup.
and then use it like this
edit ps, you might want check if you already use a powerup atm. If you start two coroutines both would set powerup to 0 after the waittime. This will propably overlap. To be able to "retrigger" the timeout you better work with timeout values which can be changed at any time.
and in Update do your timeout check: