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

Mapper and Reducer Program Using MongoDB

Getting started with Distributed SQL

Getting started with ESP8266 and MicroPython

Docker Swarm — Part 2

1 Month Review of my oculus

The golden rule of software engineering

5 must-read books if you work in IT

Brush off your coding skills using Codecademy

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

Understanding the Body Settings in Cinemachine Virtual Cameras

Instantiate and Destroy Game Objects in Unity

Galaxy Shooter 2D — Super Laser

Installing Unity and Getting Started with Game Development