Speed boost

Kinga Osińska
2 min readMay 10, 2021

--

Today, we are making a speed boost. When our player holds the left shift, his speed will increase. We will use a scaling bar to show how much is left of our speed boost. We will use speed powerup to charge our speed boost.

Add an Image, change the name to “SpeedBar”, add a Source Image, best would be a white sprite.

In the Player script add variable of type Image called _speedBar.

Add using UnityEngine.UI; at the top!!

In the Update() method when Player hold left shift increase the speed, and when he reales the key, go back to the default speed.

Add SpeedBarChargeUp() methodand SpeedBarChangeColor() method.

In the SpeedBarChargeUp() method we will charge our speed bar and call the SpeedBarChangeColor() method,

In the SpeedBarChangeColor() we will change to color of the speed bar.

Go back to the Update() method. We need to decrease our speed bar and call the SpeedBarChangeColor() method. Add an if statement to ensure that we use the speed boost only if our speed bar is charged.

Comment out the SpeedBoostActive() method and SpeedBoostCoolDownRoutine() method.

Go to Powerup script and change to method we call in the fitst case of the switch statement.

--

--