Day 41: Thrust HUD with Cool Down

Objective: Give player feedback on temperature of thrusters!

We don’t want to get the player the ability to use the thrusters the whole time they play, right? In this game we’ll limit the use of the thrusters by simulating overheating.

We’ll start with the variables we’ll need. We need the max that the temp can go before over heating, the current temp of the thrusters/engines, and a bool to know if the engines is overheated or not.

The variables are done now to increase the current temp while the left shift is being held. When we hold down the left shift we will want to make sure that the engine isn’t overheated.

While the left shift is being help, we’ll increase the currentEngineTemp by time.delta. We’ll also check to see if the currentEngineTemp is greater or equal to the maxTemp. If it is we’ll set isEngineOverHeated to true so we can’t use the thrusters anymore. We’ll also start the coroutine to cool down the engines.

In the Coroutine we’ll take away from the current temp by a certain amount every second. Once it is zero or less, it’ll assign isEngineOverHeated to false and break out of the while loop and allow for use of the thrusters again.

Next will be to connect the UI. For this I created a doughnut and turned it white.

We’ll import this into Unity and under the canvas, create a image object. In the image object under sprite renderer add this in the source image.

In the UI_manager script we will need to get a reference to this object.

Now we’ll create a public function to get the currentEngineTemp and a bool to see if the engine is overheated.

To get the image to show any amount we’ll equal the _heatGauge.fillAmount = currentTemp.
On the Image Object we created for the gauge there will be a image type. We’ll set that to filled. Method will be radial 360. Origin is where it will start filling from, I selected left but you can do right up or bottom. You can also select if you want it to fill clockwise or counter clockwise.

Next we will check to see if the engine is over heated. If it is turn the color red and keep it that way until it’s cooled down. If it is not, it’ll lerp, slowly change, from green to red based on the current temp.

Now that the UI logic is filled out we’ll move back to the player script. Under the section we check for input, we’ll call the public function from the UI and add the correct variables that are needed.

In the function, when we pass in the currentEngineTemp, we need to divide by the max temp. This will increase the fill amount of the image based on the percentage of the currentEngineTemp.

That’s all it takes to give player good visual feedback on engine temp to overheating.

--

--

--

I am passonate on learning to program and use Unity to become a skillful Unity Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bluzelle Triggers and Helps to Resolve Important Bug in Tendermint Consensus Engine

Step by Step Integration for Huawei FIDO BioAuthn-AndroidX

Having trouble keeping up with your SQL-NoSQL data sources? PartiQL for rescue!

Happy New Year! Welcome 2022 *Metaverse Monthly Report — November 2021

Test-driven Development

Perfect strangers: 5 of the lesser-known coding languages… and why you should learn them (Part 2)🧠

Quick-start spring rest-api with Cassandra

How to Choose a Managed WordPress Hosting: 7 Most Important Features

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
Tyler Smallwood

Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer

More from Medium

Day 101: Character Animation Part 4

Skeleton Enemy

Adding a User Interface to our prototype

Hidden Shortcuts to Make Level Design Easier in Unity.