Hi everyone, I'm Jeremy Gibson Bond and welcome back to the Unity Certified Programmer exam preparation course. In this video, I'm going to be looking at the solution to the audio challenge. There are lots of little parts to this so I'm just going to go through in the same order that I did it when I solve the challenge myself. So, the first thing I did was set up my audio listener, as you know, there can only be a single audio listener in the scene, and it is normally on the main camera and the scene. However, we don't really care what the camera is near and what the camera can hear, in our game we care what our player character can hear. So, we're going to move that audio listener over to her. So, I click on the main camera and you can see that I have removed the audio listener here, and I added an audio listener to the player character. The next thing I did was start looking at the reverb zones because I knew that was something that was going to be embedded into my geometry in the level. If you look at Hallway-Z, you can see I've added a reverb zones folder or empty game object and beneath that reverb zones empty game object, I have four different reverb zones. These three are all set to standard hallway, so they're kind of an echoing hallway. This one that's over the carpet is set to carpeted hallway, and that just makes it less bright and makes it sound a little bit more like we're actually in a carpeted hallway. The audio mixer in unity allows me to pipe all the sounds I'm creating into a mixing board where I can adjust the volume, and apply effects, and take the snapshot things that allow me to have different settings at different times. For this challenge, remember you did this with the cover or not uncovered snapshot. So, the first thing I did was look at the different kinds of audio I wanted to have and create a channel or a group in the mixer to hold that audio. So, I've got the master which is the overall volume then I have the music for the background music, I have ambient for the ambient sound of the security room, I have footsteps for my players footsteps, alarm for the alarm when it goes off, and security gate beam for that whining security gate beam sound. I then added the background music and the ambient sound for security room to my scene. I wanted to show that they could be put either in the Game Manager, which when we eventually have multiple levels is going to move from level to level, or in the scene itself. So, for example, the security room ambient sound belongs in the scene itself because we could go to a different setting and it would have a different ambient sound. On the other hand, the music, I went ahead and put in the game manager because it is going to be tied to the game as a whole not to the individual space. Now, that's a choice that I made, that's not the way it always has to be. I also you can see, put the audio alarm into the game manager because that same alarm is going to follow me from level to level. You can see that most of the clips are play on awake except for the alarm clip which of course doesn't play until we tell it to by tripping the alarm. So, I added an alert mode audio-player script that uses the same alert mode kind of code that we had before, it has an audio source, and just whenever the alert mode status change goes to true, it plays the audio source, and when it goes back to false, it stops the audio source, so I tie into that same system that we used in the alert challenge. Now, there's only one real spatial or 3D sound in this scene, but again, I want to give you a chance to play with a 3D sound, that is the security gate beams. Now, the audio is attached to the security gate beams and not the security gate because we can turn off the beams using the desk and the audio should go away too. You can see this plays on wake and it loops and it's piped into the security gate beams output in the audio mixer, and I've shifted the spatial blend from 2D all the way over to 3D which causes it to change based on where my player is relative to the sound. It actually also does some cool stuff like doppler effects and that kind of thing, but my player's not moving fast enough for that to matter. Lastly, we've got what is definitely the most complex part of this challenge and I thought a really interesting part. Starting off, if you look at the player deep, deep down attached to the left toe and the right toe, are little spherical colliders that extend just below her feet to touch the ground whenever she walks on the ground. So when she walks, these will touch on the ground. I've got a script here, this audio footstep collider script that looks for an on trigger inter and then tries to get the audio ground sound component of whatever her foot stepped on. If that is null, then it just returns, but if it is not null, it will go ahead and get an audio clip from the ground sound script, and then play that random clip from the ground sound script. As you can see on line 28 there in the comment, the mute next step is set initially because whenever I would start a level, her feet will hit the ground at the beginning of the level and you hear the super loud double footstep, so that just tells it to not play a sound for that one footstep, and then it gets set to false of the next footstep makes sound. Let's look at how this GetClip works for the ground sound. As you can see, there's not much to the ground sound. It just asks the footsteps scriptable object what sound it should play, so let's go look at that. Here in the audio footstep sounds scriptable object which is a mouthful is the actual GetClip where it iterates through all of the clips that it has and returns a random one. It also makes sure that it doesn't play the same sound twice in a row, so if there's four sounds on it, say it play sound zero, then it will play sound one, two, or three before it plays sounds zero again. The last thing to talk about here is the audio snapshots. You can see that the snapshot no cover has music at negative 10, footsteps negative 15, while cover has music at negative 20 and footsteps negative 25, but there's even more than that, if you look at the low-pass filter when in cover, it's cut off frequency is set to 5,000 for the music, in no cover, it's set to 22,000. What this does is it knocks out some of the brighter sounds of the music making it sound a little bit quieter and less bright. Similarly, when looking at the footsteps, you can see that in no cover the cutoff frequency for the high-pass filter is 10 Hertz, that's allows all of the low sounds to come through. Then when we go in to cover, the higher sounds are allowed to come through, everything over 1,000 Hertz is allowed to come through, which makes those footsteps sound lighter because they aren't the deep sounds to those footsteps. So that's it for the solution to the audio challenge, I hope you had fun with this one and I will see you in the next video. Take care.