Objective: Game Audio Implementation.
In the first step create an empty game object called Audio Manager and attach a new script called GameManager which needs to be singleton.
Create two new Empty game objects as a child of Audio Manager called Voice and Music. Then attach the audio source to each one.
Go to the Audio Manager script, create the Audio Source component, and serialize it. Drag and drop voice to the Inspector in the audio source field.
Create a public method in Audio Manager, with an audio clip parameter, then assign an audio source clipt with that parameter, and lastly play the clip.
Now I will go to the enemy I will create an audio clip variable, for this enemy, I want two clips. Then I will go to the damage method and play one audio when health is more than 1 and play another when the enemy has 1 health.
Then I will drag the audio to the enemy on the inspector.
Then I will go to the player create an audio clip variable drag to the inspector, and call Play clip Voice when I fire a sniper.
I have an issue, it's not an error but I want when the enemy got hit his voice should heard clearly.
To solve this I create another game object called Sniper and add an audio source to it then reduce the volume to the level am happy with. I add another variable of the audio source to the audio manager called it sniper audio source, then drag the sniper object to the inspector.
In this step go to the play voice in Audio Manager, and check if the clip name is Sniper-shoot I set the clip and play Sniper Audio Source. Else I play another audio source.
I will create another audio clip at the player script, then go to the ray cast code and check the barrier layer. Then I will add a condition to check if the collider we are hitting is a barrier and play barrier sound and don't forget to drag this sound to the inspector
I want when AI reaches the destination to have breach sound, to do this I will create another audio clip and assign it the inspector then play this sound when AI reach destination.
Last I will select the music game object then take the background clip and drag it to the inspector . Make sure the play on Awake is on and the loop option is on.
This is how I Implement Audio in my game.
See you in the next one.