Day 17 of my Developer Journey: Creating the Speed Boost Powerup

Marek Ondrej Valco
2 min readDec 11, 2021

Objective: Creating an object that activates double speed for the player.

First we will add the sprite of the speed powerup and give it the same properties as we gave our trippleshot since this is just another powerup that will just activate a different method and coroutine. Make sure to select the id number 2 so the player can differentiate between them.

Inspector window for our new Powerup
Our new Powerup sprite

Now the code. First we will add 2 variables. The first is the _speedMultiplier powerup. This is our indirect way of changing the players speed without changing the original value directly.

Speed Multiplier variable

Next we will add a bool variable to check if we have collected the powerup and to activate our method and coroutine.

Serialized bool variable

Now the method and the coroutine which we will place them in the player’s code. First the method to fire the coroutine. This is just a simple check to see if the variable is true. If the variable is true, multiply the player’s speed by 2 and start the countdown. The coroutine just counts down and once finished it divides the players speed by the speed of the multiplier.

Method and Coroutine for execution

Last but not least, we just change the code in the powerup script to change the value of _isSpeedBoostActive.

Case modification

Objective: COMPLETED

--

--