Visual Feedback — A Boost Bar

Many games feature a “stamina” system or something akin to that; the ability to speed the player up for a limited time by expending a resource. After some time, the player must wait to sprint again.

I previously implemented a simple stamina system for the space shooter example game, but without visual feedback, it is not clear what is going on to the player. Let’s fix that!

The boost stops after a bit, but there is no way to tell why!

First, a look at the boost system:

Two variables to track the current thruster value, and the maximum.

In Start, I set the currentThrusters to = maxThrusters. This ensures players always start with the resource at its cap.

In Void Start.

Next, a look at a new function, Thrusters:

There’s a lot going on here! Make sure to call this function in Update when you are done!

While this function has more than a few statements, they are very simple:

The first “if” ”statement controls the function on when the player presses shift and has thruster available.

The second “if” ”statement turns off the player’s thrusters if they let go of the shift key, or run out of thruster.

The next two statements drain the thrusters, or refill them based on whether they are being actively used or not.

The two following “if” statements set the minimum and maximum values for the thruster system.

Finally, the last statement is part of the visual feedback we are wanting to build. This will set the current value of a slider to be equal to whatever the currentThruster float variable is.

What is the ThrusterSlider.value statement? Well we need a new UI slider and to save it as a variable in our script!

Create a slider.

Position the slider where appropriate, then go back into your C# script.

New variable of type slider.

The remaining work is done in the Unity window, as you set up the color and design of your slider. This is mainly going to be trial and error as you discover what you want your design to look like.

I went for a simple blue bar, which drains to red as the thrusters lose fuel.

Let’s see it in action!

Now the player can ration their thrusters as needed.



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
Jack Leavey

Jack Leavey

I am a software engineer with years of experience branching into game development, specifically in Unity. Follow along for guides on creating game mechanics!