Determining How Long Powerup Effects Should Last

Let’s say we have a triple shot powerup

  • Attach a Powerup script to the powerup prefab
  • In Powerup script, in OnTriggerEnter, create a way to communicate with Player script to activate the powerup
  • In Player script, create a private bool variable (the bool default value is false) to check if the powerup is activated
  • Create a function to change its value to true and call the coroutine
  • Create a coroutine to define how long the powerup will last. We will use a 5 seconds delay using
yield return new WaitForSeconds(5f);
  • Change the bool value to false in the coroutine
  • Start the coroutine: it can be started in Start( ) function or in another one, in this case, in ActivateTripleLaser( )

--

--