Please: next time just copy the code here in code-tags. Then I could copy&paste which allows me to play around with it. Then I also could check if my hint is correct ;-).
But ok - I think I located your problems. Let me go through it one by one:
- You check for the Space-Bar and you starte the coroutine fireRapidly() + store the IEnumerator in a variable.
- You have an else-if-block doing the same check as in the if before. So this block becomes ignored
- Follow up comes another if which does not stop fireCoroutine. You have a bug here: you should pass as parameter the variable poweredFiringCoroutiner. What you do here is to create another IEnumerator (which has not been started as coroutine) and stop it (makes no sense ).
So what you probabbly want to do are the following steps:
- Merge the first and the second if. Depending on the canTripleShot-flag you either create the one other fire-mode. Cause only one can be active at the same time you also need only one variable for that.
- Pass the variable to the StopCoroutine-Call when releasing the button
Checkinig a boolean if it is true is btw a redundant check. So instead of: if (variable == true) you just could write if (variable). And you also can shorten if (variable == false) by using an ! in front of the variable:
The ! is btw very usefull in case when you want to toggle a boolean (so that true becomes false or false becomes true). Which can turn such code:
into a simple one-liner: