Improving Thruster Feature with UI Elements in Unity

Helping the player to use the thruster

Objective: Create a UI Bar element to see the Thruster fuel

First step is to create a UI Slider element.

Then we have to change the position to make it fit with the other UI elements of the game.

The next step is remove the value hadler (because we are gonna control it through script) and change the colors.

In the player script we have to create 2 variables, an float variable to represent the fuel and a bool variable called _fuelCooldownActive for the cooldown system for the thruster.

Then create a coroutine ThrusterCooldownRoutine that gonna change the value of the fuel cooldown variable, then wait 3 sec and it is gonna increase the value of the fuel until it reach 100.

In the update function we are gonna add 2 conditions, if _fuelCooldown is false, if fuel id greater than 0 (and if player presses left shift key) the thruster is gonna be activated.

Then in the UI Manager script let’s declare variable to get the reference to the slider and create a function to update the value of the slider (this function its gonna be called each time the player uses the thruster and when the cooldown system updates the value of the fuel).

Good to go!! New thruster feature with cooldown system ready to use.
