Afterburner overload: cooling down thrusters

Objective: Allow thrusters to overheat if used too long, requiring a cooldown system before they can be used again.

Thrusters now overheat when depleted and must wait to cool of before recharging.

Create an UI image for the afterburner indicator, naming it Thruster_Energy. Anchor it to the top left move it to just under the life indicator at roughly (x 100, y -90, z 0). Attach the Thruster_00000 sprite as the source image from GameDevHQ Filebase. Change its z rotation to 90 and set the height and width as shown below. Change the image type to filled, fill method vertical and fill origin top. Since the image is rotated this will fill right to left.

UI image for afterburner status.

In the UI_Manager, use a serialize field to assign Thruster_Energy to the private Image _ThrusterEnergyImage variable. The script below displays a portion of this image using fillAmount based upon the float variable, energy, provided when the function is called.

Public UpdateThrusterEnergy function in UIManager script

The afterburner function is provided in the Player script and requires the following variables. The _afterburnerDuration is a float used to set the time the afterburners can remain lit before overheating and is also the cooling time. The _canAfterburn float tracks the time for the cooldown after overheating.

Variables required for afterburner cooldown

Player script contains the C# code for the after burners, see below. If the left shift key is pressed and the afterburners are not overheated player velocity increases two fold. If the player holds the key down for the _afterburnerDuration, 0.5 seconds, the afterburners overheat and will not recharge for 0.5 seconds. The _afterburnEnergy variable tracks the time until overheat, and _canAfterburn indicates overheating if greater than the current time, i.e. Time.time.

Code to turn on afterburners and check for overheating in Player script.

Below is the code for recharging the afterburners. If the left shift key is not held down and the player has used the afterburner for less than 0.5 seconds then recharge occurs immediately. If the afterburners have overheated they will not recharge for 0.5 seconds.

Code to torn off afterburners and recharge them if not overheated in Player script.

The _uiManager is accessed and null checked previously in void Start and is used to update the UI using the UpdateThrusterEnergy function, passing the amount to subtract from the fill amount, Time.deltaTime / _afterburnerDuration.

Software engineer