Hello guys.
Welcome to the video.
In this one we're going to set up audio effects for the game.
Going to be pretty easy to do actually.
And I guess we should start by doing something in the script folder.
I didn't do it in the last video for some reason.
Again, but let's just do it now.
Let's do folder and let's call it managers.
And I'm going to take camera manager, game manager and skin manager and drag them here to managers.
And also I think I can make folder for cameras.
Yeah, let me do it.
Let me do folder camera and I'm going to take these two and drag them here.
Uh something else.
Oh there is difficulty manager.
So you can take it.
Bring it to managers.
Nice.
Now.
No, no.
Now let's make audio manager again.
I'm going to do it in managers I'm going to make C sharp script audio manager.
This is good.
Now we need to go ahead and make a game object that would serve us as audio manager.
Oh, there is a script.
Let me drag it to scripts.
And let it be there.
It's okay.
So we're going to create empty Audio manager.
Very nice.
And we need to add component of audio manager.
And we're going to open the script.
I think we're not going to destroy the audio manager on load, because there may be the case where you
want to play the music and you don't want the music.
Stop between level transitions.
Otherwise, every time you restart the level, for example, when you die, you're going to start song
from the beginning, and that can be very noticeable.
So let's go ahead and do, uh, public static audio manager instance.
Then we're going to do a wake.
Don't destroy unload this game object.
And then if instance is equals to null then instance this else we're going to destroy this game object.
Nice.
Uh, now let's take the header.
Let's make header audio source.
I'm going to call it that.
And we're going to need serialized field private audio source array for sound effects.
And I'm just going to call it SFX.
All right.
So we're going to take audios.
And we're going to assign them into the field of audio source with the name SFX.
And every time we need to play the audio, we're just going to call audio source with a certain index.
It's going to make it much easier for us.
Now let's go ahead and make.
Public void.
Play a suffix.
And here we need to pass int a suffix to play.
Very nice.
Now first of all we want to check if the number we're trying to get is within range of the array we
have.
So I'm going to do.
If suffix to play is bigger or equals to a suffix dot length, then I'm going to return.
And if no I'm going to do suffix with a suffix to play dot play.
Also, there may be the case when you need to stop a suffix.
I don't think it's going to happen in this game, but maybe you have some long sound effects that you
will find later on.
So for that purpose you could use public void stop suffix and you would just pass int a suffix to stop.
That would do a suffix suffix to stop.
And I'm not checking index of Linux here, because if you could play this sound effect, obviously you
could stop the sound effect, right?
Yes.
Okay.
Believe me or not, this is enough.
Now let's go back to unity and we're going to go to asset and make a folder for audio.
And you're going to open the archive that is attached to this video.
Because there I've collected some sounds for the game.
It is not the best sounds you could find, but I think they'll work pretty much okay for the game we
have here.
In the end of the day, we just make a study project, right?
So it's not supposed to be perfect and we just need the system itself.
So there are the sounds and we're going to use them as example.
And in the end of this section I'm going to show you where to find more sounds.
If you like I'm going to show you places, different websites.
And also I'm going to explain a couple of things about sound effects.
So let's just use these for now.
Um, I have this menu select sound and let me check if I'm recording them.
This is important.
Okay, I think I do record sounds.
Let me try.
Yeah I do okay.
So these could be used for menu selection for example.
Right.
And other things for the things they are like named for.
Right.
There's death finish jump.
So on first of all we need to take all of the sounds here.
We need to drag them into the scene like that.
Then for all of them, we need to uncheck play on awake.
If you don't do that, all of the sounds will be played when you start the game.
If you cannot hear the sounds, you need to click this icon over here because your game might be muted.
Let me try again.
Oh, wow.
Yeah, that was crazy.
So we have to disable play on awake over here.
Then you would have to adjust volume for different sounds.
That is more about, you know, setup of the sound.
Like you need to do detailed setup for the sound effects, because sound is very important for the game.
But that's not the most important thing right now.
For now, we just need to make a parent for these sound effects.
I'm going to make parent sound effects.
And then I'm going to make parent for this one.
I actually we don't need to I'm sorry.
We have audio manager.
So let's drag it and make it as child of audio manager.
Nice.
Now for the sound effects.
We could manually drag them here.
Or we could write a script that would collect all of the sounds.
And I think I'm just going to drag them.
Why not?
Let's just click the lock it over here and let's take the sound and drag them to the array like so.
Perfect.
Now you can see each sound here has a number, and if you want to play a certain sound, you just need
to pass the index number over here.
I mean from here example we can go to canvas and find a place where we click buttons.
For example, we click a button every time we switch UI.
So I'm going to do Audio Manager dot instance play SFX and we need to know the number.
So I'm going to pick into unity and see that.
There is this menu select with number four.
So I'm going to play it number four.
We also need to play the sound when we start new game.
So I'm going to duplicate it, place it here, and maybe we can duplicate it again and call it when
we continue the game over here.
Just like that.
In essence, I think.
This should be okay.
So now we have three places we call the sound.
Right.
Switch UI new game and continue game.
I'm going to save this.
Go back to menu and go to play mode.
And I'm clicking.
New game.
There is a sound.
These two supposed to play sound as well?
I kind of forgot we're going to fix it.
And.
There was no sound.
So, um, skin selection button have to play sound.
Let's go to skin selection.
Uh.
Over here.
I'm going to play a sound here and on the next screen and on the previous screen like that, I could
call it in the update screen display once, but this method is called at the start as well.
And I guess we don't need to play sound then.
So I'm just going to call it three times here, here and here.
Perfect.
Let's save this.
And let's go and try that again.
Oh, no.
Wait.
Elsew level button.
The level button.
Level button is over here.
Let's go to level button.
And every time we load the level.
You're going to play sound.
Okay.
That's good.
Now this will work.
Also want to go and make the sound lower in volume because I feel it's too loud.
So I'm going to do point four and let's just check it.
Looks okay to me.
All right.
We are in the game.
Perfect.
Now let's go to the next video.
I'm going to show you how to set up in game sounds.
And also I'm going to show you how to improve sounds so they can sound a little bit different every
time you use them.