Mobile Game Progression

Adding Sound effects to our game (part 2)

Continuing on from the previous article where we added background music to our game along with adding UI sound effects to our buttons. In this article we will focus on adding Sound effects to our player and enemies. There are several things that we will go over:

  1. Adding sound effects when our Player jump/walk/attack/gets hurt/dies
  2. Adding sound effects for our enemies gets hurts/dies
  3. Adding sound effects when the player collects the Diamonds.

Adding the Sound Effects:

What we need to first within our Audio Manager we are going to create new empty game objects containing new Audio source components for each sound effect. This method is organized but isn’t optimized.

For every sound effect other than the background music, we want the “Play on Awake” to be unchecked.

Player Script:

Inside the player script we are going to create new handles for all the Audio source components.

Death and Damage Sound:

Starting with the damage and death sound effects, we are going to locate the “Damage” method and insert the damage Sound whenever the player gets his health deducted.

In the Death sequence within the Damage method, we are going to insert the Death sound effect.

Sword Swing Sound:

In the void Attack method within our player script we are going to insert the sword sound effect.

Diamond Collection Sound:

In the Add Gems method we are also going to add in our Diamond sound effect.

Foot Steps Sound Effect:

For the foot step sound effect, I am going to introduce another method to trigger audio clips. We are going to store several audio clips within an array and have the audio clip play a random clip.

First we are going to get a reference to an Audio Source that doesn’t contain any audio clip yet. Then we are going to create an Audio Clip Array and name it footstep.

In the start or awake method we are going to assign the audio source from the audio source component on the player.

Then during the movement method we are going to select the audio clip from the Array with an randomizer and assign it to the audio source. Then play the audio clip.

I also created a boolean to track whenever the player is moving, since I only want the footstep sound to occur whenever the player moves. I track whenever my velocity.x doesn’t equal to zero I set the isMoving bool to true, else it should be false.

Back in Unity we are going to make sure our footstep array has correct amount of elements. In my case, I only have 2 audio clips so I set the count to 2, then drag in the two audio clips into the slots.

Now when testing your game, you should hear the proper sound effects.




A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

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

Recommended from Medium

Microsoft Engage Mentorship Experience 2021

Filling holes in 3D mesh using Meshlab

Apache Kafka: A Brief Introduction and Implementation using Python

Banyan Tree-connecting clubs and students efficiently!:

SOAP and GraphQL should we give it a REST?

Common mistakes on the initial state of software development

Software development projects; common mistakes entrepreneurs make on the initial state

The road to Babylon for AirGap

How to edit your hosts file (mac edition)

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.