Preventing infinite attacks - seems unnecessary

My code has deviated a little bit from the tutorial but not so much that I think the point isn’t valid…

We call StopAllCoroutines so that we don’t have more than 1 cooldown running at a time but ActiveWeapon is a singleton, there is only ever 1 of them and the cooldown is only called after an attack which only happens if isAttacking=false, which only happens at the end of the coroutine. Therefore, it seems to me that its not possible for more than 1 cooldown to be running.
We then call the cooldown routine when swapping weapons to prevent rapid cycling of weapons leading to infinite attacks without cooldown but if we didn’t call StopAllCoroutines then the cooldown is still active and running. If you hit with the sword then change to the bow, you can’t fire until the sword cooldown finishes.

The way its written, you have to wait on the cooldown of the new weapon after switching, before you can use it - which is a choice, and a valid one but that’s not how its explained in the video.

You’re quite right, it shouldn’t be possible for two cooldowns to be running at the same time. In this case, this is what we call a redundant assurance. It’s not strictly speaking necessary, but in the unlikely event that something does go wrong. You can remove the StopAllCoroutines() line quite safely if you wish.

Privacy & Terms