What you will learn
In this Unity tutorial, we will learn how to effectively utilize the game engine. Over the tutorial, we will learn how to use the Unity editor interface as well as how to navigate in the scene view. From there, we will learn how to import assets and how to create prefabs. Then we will shape our level even more by adding character controllers, colliders, lights, materials and physics. We will then finish the tutorial by learning how to use scripting in order to make our level interactive.
In this lesson we'll learn how to add audio to our game level. So what we're going to do is we're going to add an audio bit to our fire here, just to make it a little more interesting. So let's go to our Audio folder. And we're going to choose Pod Fire. You could see that we have some audio sound waves here. And you could actually preview this, if you want to, before you actually bring it in. And what we're going to do is just click and drag this audio file right on top of our fire object, our fire particle. And what this is going to do is parent itself right on top of our fire. Now if you don't want your audio clips to be parented, you could actually just drag them off into empty space. And then they'll just be audio files in the scene. But in this case, I'm going to put it right on my fire. And now I can access that audio file just by clicking on it. And you'll see that it's associated itself to the smoke of my fire. Now with smoke selected in my hierarchy, and I go over to my inspector and I scroll down, I can see that the audio source has been tied to this object. So the first thing we see is the pod fire. So if you accidentally selected the wrong audio clip, you could just simply click on this Option button to bring up your Select Audio Clip dialogue box. And then choose Debris Fire if this is something that you're looking for. Now I want to stick with this pod fire. And I'm just going to close this out. Now you'll notice that this says, this is a 3-D sound. And what that means is whenever you are walking around inside of your game level, if the audio source is to the right of you, you're actually going to hear it more predominately in the right headphone. Now if you are facing to where the audio clip is to the left, you're going to hear it on the left, so forth with the front and the back. Now we can mute this audio clip if we want to just by checking this. We could bypass any effects that are associated to this audio source. So for example, we can actually add in what's called a reverb zone. And if we don't actually want to hear that, we can just turn that off and bypass that effect. Now we have Play on Awake. And what this is going to do is play the sound when the scene loads. So whenever this happens, we're going to have this play automatically. And we may have an instance to where we don't actually want this to play whenever the scene modes. We want it to actually play whenever our fire starts. Let's say we've got that tied to a trigger or something like that. So we want to uncheck that, if that was the case. Now I do want my fire clip to go ahead and play over and over again. So I do want to go ahead and check Loop. Now we're up to a couple of options here. You might be wondering what Priority is. And what this does is sets a priority of your audio clips. So right now this audio clip, which is pod fire, is set to a priority of 128. And this is the default value. Now if we wanted to take the highest priority, we would set it to zero. And if we wanted to take the lowest priority, we'd set it to 255. Now the reason that we might want to do this is because we might have several audio sources going on at one time. And let's say we want our enemy's audio source to be more predominant and have a higher priority than things like our background noises. So we would set their audio clip to zero instead. Now we have Volume, which is pretty self explanatory. It ranges from zero to one. We have Pitch, to where we can actually raise the pitch of this audio level. And it will actually play this audio clip faster. Now we have our 3-D sound settings. And this is the meat of our audio sources. We have our Pan Level, which is going to basically-- well, you can see here. It says it affects the pan and attenuation of the sound. Zero equals panning attenuation. And it's going to be ignored. So if we take this to zero, it's going to ignore all of our attenuation that we have in our 3-D sound We have Spread. So it's going to actually spread the sound out in your speaker's face. We have Doppler Level. We have our min and our max distance. Now this is what I really want to get into in this lesson, because this is how we can actually make our sound fall off as we get further and further away from it. So our minimum distance is going to be one. And at one the audio clip is going to play at a full 100% volume. Now whenever we get down to the max at 500 or more distance away, the audio clip is not going to play at all. Well, that's not necessarily true. And I'll explain why that is here in just a moment. Now we have our Roll Off mode there. Sorry about that. And we have Logarithmic, which is our default. And you could see how this logarithmic pattern is working here. So as we get further and further away, it's a very steep drop in the sound level. Now if we go to Linear Roll Off, you'll see that it's a very linear drop off. Nothing like that logarithmic. And then we have Custom. And we can actually customize a roll off of our sound. Now we're going to stick with the logarithmic on this one. And let's test out this audio. Now one thing that you want to make sure of whenever you're playing this level is, you might have a warning down here at the bottom saying that there can only be one exact audio listener in your scene. And you're going to get that warning whenever you drag in a first-person controller or third-person controller. And if you haven't deleted that main camera out of your scene, you should probably do that now. So in your hierarchy you might see something that says Main Camera. Go ahead and delete that, because we have a first-person controller that's going to take care of that for us. All right. So now let's play test this and see how this audio is working out. So we can hear it. And as we're getting further away from it, we're going to see that our audio clip is begin to fade away. Now right now, it's not really fading all that much, simply because our max distance is really, really high. So let's take that down. So let's take this down to 50 on this one. Now remember, whenever I told you about the level of the volume never getting down to zero. And that's actually true. Let's take a look at this key frame right here. Now whenever we get to that distance of 50, you can see that this key is not exactly on zero. So what that means is that we'll always hear our sound effect no matter how far away we get from it. And it's always going to be there just barely. So if we want to take it out completely, let's take this down to zero at 50. Now just to make things nice and neat, I'm going to pull this down a little bit too. All right. So now whenever we go ahead and play test our game, we've got full 100% audio as we get really close to it. The further we get away from it, the less sound we have. So now as we get pretty far away from it, we can't hear that any longer. So you can hear that in your left speaker or headphones. Now we're still not able to get quite far away enough. So we could take this max distance down even further if we need to. So I'm going to take it down to 25, just to cut that in half. Let's play test this again. And now you can see that we can get away from this much easier. So right now, we're at a point to where we can't hear that audio at all. So that's how we can actually control audio and adjust its attenuation to actually make it real life. We're getting away from it. The further we get away, we can't hear it any longer. So in our next lesson, what we're going to do is we're going to get into the animation view of Unity.