Powerup Series: Limiting the Duration
Now that the Player can collect the powerup and start firing Triple Shot lasers, we need to limit how long the Triple Shot effect lasts.
Writing a coroutine
In the Player script, we’ll add a new method that returns an IEnumerator to create a coroutine. First, we’ll enable the Triple Shot Active switch. Next, using the yield return keywords, we can pause the coroutine for a few seconds and then, disable the Triple Shot Active switch.
Starting the coroutine
Since the Player already has a public method to Activate Triple Shot, which is called by the Powerup script on collision, we can update this method to start the Triple Shot Routine written above.
Now, when the Player collects the powerup, the Triple Shot effect only lasts three second — then the Player returns to firing a single laser.