 Now so far we've just been playing audio through the audio clip of an audio source playing on a wake But of course what we more often want to do is programmatically trigger when sounds play in code and we can do that through the methods of audio source Including play pause unpause and stop which are pretty self-explanatory, but there's also play delayed where you specify time and seconds to wait before starting the sound and Play one shot the regular play method plays the clip specified in the audio clip property of the audio source Whereas with play one shot you can just specify any clip to play through that source And you can also specify a volume scale for that for that clip So in fact with play one shot you can have multiple sounds playing simultaneously through one audio source If we have multiple sounds going and we hit pause they all get paused and we'll all be resumed with unpause And if you call stop all sounds currently playing through an audio source gets stopped There's also the static method play a clip at point where you don't even have to have an audio source to play an audio clip It'll just play at that position in space as specified here though understand with this method because there's no actual audio source You can't feed the output to a mixer. You can't specify its pitch or any of the spatialization properties So it's a much more limited way of playing a sound though in some cases. That's all you need So now looking back at our script We have two clip properties clip one and clip two and an audio source property And so on our object, which has an instance of this audio demo script We hook up clip one and clip two with two audio assets and we hook up the source to be audio cube gray That's this gray cube in the scene which has its own audio source So now we'll have two audio sources in the game the red one and the gray one So when this instance of audio demo is created Unity will take these sound files and create audio clips which it will set to clip one and clip two And it'll take the the audio source of that game object and set it to this source property And then in our update when the user hits alpha one We'll use play one shot to play clip one on source when it alpha two that plays clip two on the source the gray box When I hit Z it invokes the play method on the source X will be pause C will be unpause and V will be stop So now if we go back and play the game We have tinny Prokofiev coming out of the red cube come over to the gray cube and if I hit one We get gongs. I can hit it multiple times and it's just overlapping gong sounds You can't tell do super well, but they're overlapping I'm gonna hit V to stop all those and If I hit Z to play Well the clip associated with this gray cube is Let's see which one we set that to be we said that'd be Beethoven Oh, they're audio source. Yeah, it's this Beethoven I'm gonna hit V to stop and if it to clip two was set to be a different audio clip. It's this right game music I'll get further back. So it's not so loud If I hit X it pauses Z will unpause if I do some gongs and pause and Resume notice the the gong sounds everything paused everything coming out of the audio source paused and then it resumed and Likewise if I bunch of gongs and hit V they'll all stop together So stopping stops everything being emitted through the source all the clips playing Yeah, and also understand if it's Z to play Plays the Beethoven if I hit it again It effectively jumps back So for the one audio clip clip Repeatingly playing Sets it back to the beginning, but that's not the case if I do play one shot So hit two here. I'm gonna stop and hit two multiple times. So first once And then again and it's the same clip overlapping. They're both playing simultaneously very annoyingly. So I'm gonna stop Okay. Yeah, so That one special audio clip properties its behavior is a little different in regards to how play works So be clear that for any audio source you don't really have to set the audio clip to anything you can just leave it to none and You can just use the audio source to play with play one shot instead of ever using the play method and In some cases that's appropriate because maybe you have many sounds coming out of one position in space Though if you want to independently control various properties of how the sounds are played you're gonna need multiple audio sources and Do understand that you can give multiple audio sources just any one game object So you can have as many audio sources on this one game object as you like and that way you can configure them independently So they have different settings and you'll have more control that way Also understand that loading audio clips in this way This is the easy way to do it for sure and it's probably what's most commonly done but sometimes you want to have control over how exactly the audio is loaded because maybe you want to manipulate in some way and Sometimes you want to actually procedurally generate audio data rather than loading it from any file So in that case there is a way to manually create audio clips There's no public audio clip constructor So you can't use new to create audio clips But there's a static create method which you use and then I won't go to the details But there's a way of then loading audio data to create your audio clips The way we did it though is of course much more convenient because doing it this way Unity will load the audio asset and make an audio clip for us So now I've removed all the mixers, but there's another way of applying effects to your audio sources You can add a filter component here I'll do a distortion filter on this red cube And because it has an audio source this audio filter applies to that audio source when it plays sound Let's see. Let me set distortion level something more noticeable Point eight there. Let's see. So now if we play the game Yeah, it sounds pretty distorted to me so there's a distorted Prokofiev and Understand you can also apply these filters to the the audio listener game object and it'll affect everything that reaches that audio listener so here if I add a Echo filter, let's see that should add up pretty decent echo. Let's hear Yeah, it's pretty acuity though understand that these filters don't do anything we can't do with a mixer Mixers are actually just a more general and flexible version of accomplishing the same thing and in fact you'll notice the list of Filters is relatively limited there were more effects for mixer groups than there are filter components Because filter components are actually the old mechanism Mixers and mixer effects are the new mechanism the more recent thing So they're they're generally what you prefer in a modern game though sometimes arguably these filters are just more convenient to use so maybe you'll still use filters, but Mixers really are the more modern mechanism Lastly, let's add here an audio reverb zone create a game object with an audio reverb zone component and It doesn't show up particularly well here But if you zoom out it will see there's a radius is this light blue outline of two spheres This is showing the interior radius the min distance radius This is the max distance radius and the idea is that You know, let me actually shrink these downs. So it's more noticeable effect There I'll try and position that between the boxes. He ends about right There we go, and we'll shrink that max distance a bit too. So we start outside of it So this is defining a bounding sphere in which these reverb effects start to apply when the audio listener enters these spheres and Within the min distance sphere, it's the full effect Whereas if we're in the outer sphere, but not the inner sphere, then it's a it's partially applied When we enter the max distance radius, that's when the effect kicks in and the closer we get to the min distance radius The more pronounced the effect. So we have various different reverb presets and we want the effect to be quite noticeable So I'm going to make it Underwater that one's quite noticeable that we have to do one more thing here for our two audio sources The reverb zone mix if it's set down to zero then reverb zone has no effect. So we obviously want that to be Full effect. Actually, I don't know why it goes beyond one. But anyway, it does so I'll make it one Same thing here. I'll make this one And now we'll play the game We're starting outside the reverb zone But I'll enter Well, I can definitely hear it on my footsteps and I can kind of hear in the Prokofiev Yeah, it's kind of there. It's more noticeable with the lower frequencies that occasionally kick in. Let me try the gong Yeah, that sounds pretty underwater to me I'll stop that and then Yeah, the reggae is pretty underwater too so Because our audio listeners inside that reverb zone, that's why we're hearing that effect applied to all the the sounds that reach our listener At least the ones where the reverb zone Mix is non-zero Now it may have occurred to you that these reverb zones are spherical But what if you want to have a reverb area, which is not a sphere? Like say if you have a rectangular room if I enter the room the reverb should kick in But it shouldn't reverb outside that bounded space that rectangle So it's a little awkward if you try and solve this problem using reverb zones You can kind of hack around it by using triggers to enable and disable your reverb zones, but it's a hacky solution I think the best solution is well in audio mixers We have an SFX reverb effect which has all the same effects we can apply so we can apply any kind of reverb through audio mixers that we can do with reverb zones and So rather than using reverb zones at all We just have trigger colliders which when our audio Lister enters those trigger colliders the trigger will enable these reverb effects on our mixer So we can get reverb without reverb zones entirely And if you really want to do this properly you would have a transition threshold where you have the interior trigger space But then a trigger threshold like when you go through the door such that you would do the Calculation of well how close am I to the reverb zone and within a certain distance It'll kick in some reverb until eventually hitting the full reverb when you enter the full trigger zone So again, we actually really don't need reverb zones We can get the same effect using mixers and trigger colliders And that generally I'd say is actually the proper solution in most cases because the common case where you want reverb is within Rooms and rooms are usually rectangular So it's just a lot less clumsy if you can define precise spaces Rather than trying to approximate with spheres which can get pretty clumsy quite fast