Unity Basics: Determining How Long Powerup Effects Should Last
Powerups in a game should have some sort of limited duration, otherwise our game would not be challenging at all. We can achieve this by using coroutines. We have already used coroutines for the spawn manager to spawn objects every 5 seconds. Furthermore, we can also use coroutines to specify how long we want the effects of powerups to last.
To specify whether our powerup should be active or not, we can use boolean variable.
The next step is to create coroutines for powerups.
For both powerups the deactivation countdown is set to 5 seconds, for triple shot we simply activate the function and deactivate it after the specified time. For speed powerup we increase or decrease the speed variable by multiplying or dividing by the speedUp variable respectively.
As you can see, curoutins are quite useful and very commonly used in Unity.