Speed boost

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store