Creating a Thruster Gauge Feature for our 2D Galaxy Shooter Game in Unity-Part 03!

Objective: To finalise our Thruster Gauge feature by adding in some audio cues for our player to give them a greater experience!

We will continue to work in our ‘ThrusterController’ script so open this up and let’s create some AudioClip variables that we are going to use by dragging and drop the audio clips from the Project window into in the Unity Inspector window:

Now from within our Update() method as we need to be detecting player input, we are going to call a method that is responsible for playing the audio sounds called PlayAudio():

We are now looking for GetKeyDown() as we only want it to return true, once, during the frame the key is pressed. If we were to put this inside GetKey(), which consistently returns true while the key is held down, we would be calling this method 60 times per frame and constantly restarting the audio clip. So when the user presses the left shift key, it will call a method that simply assigns the _thrusterBoosterClip to our AudioSource AudioClip slot as shown below:

As you can also see at the end of the clip, a new clip gets assigned (_overloadAlarmClip) as I held the key down until my thruster gauge was at 0% which is when our existing thruster overload coroutine starts and within this, I have added our PlayOverloadAlarmClip() method that simply plays the _overloadAlarmClip (shown below). Once the coroutine has finished, then we call the PlayThrusterRechargeClip() which again simply plays the _rechargeThrusterClip.

Below we have the methods that are called for playing the separate audio clips. As you can see, they all have a different volume level as this was done to try and balance the correct levels in the game and not have one clip play strongly over the top of other audio clips.

We have now fully implemented the Thruster Gauge feature in our game using Unity’s UI Slider! This took a few more articles then I would have liked to get this across, but it was such a fun, complex feature to implement that I needed to go into some detail!

Next, I will be looking at introducing an Ammo Clip feature into our game to give the player limited ammunition, whilst providing them with an Ammo powerup that will reset our Ammo Clip. Stay tuned!




Passionate Unity Game Developer

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

Recommended from Medium

Reduce your BigQuery bills with BI Engine capacity orchestration

Handling File Systems with PowerShell

How to choose your right IoT Application Development Vendor?

How to enhance Procore construction project management system with the Slack collaboration tool.

Bi-Weekly Progress Report: June 22— July 5, 2020

Start Working on Side Projects Today!

Head First Java — Chapter 7

A Byte of Code Issue #84

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
Chris Hilton

Chris Hilton

Passionate Unity Game Developer

More from Medium

How to Make the Camera Shake Using Impulse Listener Extensions in Cinemachines Virtual Cameras

Automate Player Input with Unity Test Runner and NSubstitute

How to make a Mario Kart game with Unity

2D Mobile: Loot System