Thruster: Fuel and a Scaling UI Bar

Chris Kirts
2 min readDec 10, 2022

--

Goal: create a fuel system to limit thruster use and implement a UI element to show player levels.

As it sits my player can thrust infinitely making the speed powerup close to pointless. So I’ve decided to implement a fuel system that drains quickly while in use, and recharges very slowly over time.

The Slider element of the UI is my solution here. I deactivate the knob element as I want this to just be a fill bar. I change the fill color to red, set a max value to 30, change the background color to light blue, attach Fuel text over the whole thing.

Looks very nice, right? Hold Left shift and you get this:

The code for this is pretty straightforward. I first made a reference to it in my UIManager so I could easily access and modify the value in real time. I made a public method within the UIManager which looks for a float value to assign to the Slider fill portion.

This will set the _fuelValue to the fuelValue sent from the player script. in the Update method we have

_fuelBar.value = _fuelValue;

_fuelBar is the handle I made for the Slider object. so it’s update it each frame to the current value.

--

--