Day 19: Speed Powerup Behavior

Boqin Zhang
Jan 23, 2023

--

The speed powerup is going to change the behavior of the player by giving it more speed. So, we have to work in the player script. Let’s add a boolean to check if the speed powerup is picked up and a speed multiplier.

Player Script, Public Class

Like we did for the triple shot powerup, we need a function to change the player’s speed. The function MoreSpeedActive() is going to:

  1. Change moreSpeed to true
  2. Multiplies the speed by the speed multiplier
  3. Start the power-down coroutine
Player Script

The power-down coroutine will:

  1. Let the power up run for 5 seconds
  2. Set moreSpeed back to false
  3. Divide speed by the multiplier so that speed is back to normal
Player Script

Now in the powerup script, have the speed powerup case call the MoreSpeedActive() function.

Powerup Script

Now our game has two working power ups.

--

--