‫Welcome back.
‫And this video, we are going to add the sounds to our game.
‫And for example, you can find sounds on open game dot org.
‫And there I searched for example for sound effects and here I hear I left the licenses as they are.
‫If you want to know more about licenses, I would recommend to check out the license details on the
‫page.
‫So I search for ball and I found this ping pong or three ping pong sound a bit style.
‫And that's the sound that you could use.
‫For example, for the ball whenever it hit, it hits a wall.
‫And then you can simply generally check out the sounds that you like.
‫If you would like to use the exact same sound that we have in our project, you can download the project
‫and just use the sound assets.
‫All right, so let's go ahead and create a new folder and I'm going to call that one resources because
‫I want to drag everything except my scenes into my resources folder.
‫So I drag that one in there and do the same with the prefabs, the materials and the scripts.
‫Now what I will need to have is a new script onto my ball.
‫So let's go to the ball game object and create a new script here.
‫So use script and I'm going to call that one sound controller because that's what it does.
‫It controls the sound in here.
‫We only have one simple thing.
‫We need an audio source for our wall and we need an audio source for our record sound because these
‫are two different sounds that we are going to use.
‫And what I want to do is I simply create those two public audio source wall sound and public audio source
‫record sound.
‫Now, every time that there is a collision, I want to call one of those two sounds.
‫So I'm going to create a void on collision.
‫Enter to DX method in here.
‫So if the collision game object that name.
‫So the name of the game object that we collide with is equal to racket player one or is equal to record
‫player two.
‫So I'm just going to copy that and check out here Record Player two.
‫So if that's the collision, then please go ahead.
‫This dot record sound dot play.
‫So please play the sound.
‫And else it means that we hit a wall.
‫So please play the wall sound.
‫So this thought wall sound dot play
‫and that's it.
‫That's everything that we do in here.
‫So that's going to be our sound controller if we check out what the sound controller does here.
‫So as you can see, it expects after a little while, after it has loaded everything, it expects a
‫wall sound, which is an audio source and the record sound, which is an audio source.
‫Of course, we don't have them yet.
‫So you either, as I said, find them online and download them, or you just use the sounds that we
‫provide.
‫So create a new folder, call it sounds.
‫Now let's drag those sounds in there.
‫So I'm going to open up that folder and you can simply drag from the other project.
‫So we have the record sound and we have the wall sound, and now I would like to drag them just right
‫in there and I drag it over and as you can see, it doesn't apply it and that is because it expects
‫an audio source.
‫But those ones here are simply raw audio files.
‫So in order to get the audio sources, we need to create them in here.
‫So I create a new audio source onto my ball.
‫So right click on to the ball audio, audio source.
‫And the first one I'm going to call Racket Sound, and then I create the second one.
‫So create audio audio source and I'm going to call that wall sound and now we can drag those audio clips
‫in there.
‫So for the record sound, I'm going to drag that one just right in there.
‫And for my wall sound, that is the same thing.
‫So let's drag that in there.
‫Now the play on a I deactivate it, otherwise they will automatically play whenever we start the game.
‫And that's not something that I want.
‫You could, by the way, let's just check it out.
‫Record sound, let's activate it.
‫Let's play the game.
‫Let's see if the sound comes up.
‫And as you heard, the sound came up real quick.
‫So that's what Play on Awake does.
‫So I deactivate it.
‫If you activate loop, it will constantly run the sound all over, over and over again.
‫So now it won't because I didn't activate play on Awake.
‫So let's do both.
‫And you will see that it will automatically run this annoying sound.
‫So let's deactivate both of them.
‫Great.
‫So now let's drag those two, and I'm going to drag it up here so that I can drag it easier.
‫So let's drag the racket sound.
‫And as you can see, it moves over the inspector moves to the racket sound.
‫So if you want to still move it over and sometimes you just can't get it done because accidentally the
‫game object that is in the inspector changes.
‫You can simply lock it here at the top right side.
‫So here there's this little button.
‫Now it's locked and now I can drag the racket sound in here.
‫Actually, I dragged it into the wrong one.
‫Let's drag it in there.
‫And now let's drag the wall sound into there as well.
‫All right, now let's unlock the inspector and let's check our game if the sound works right.
‫They are our record sound and we have the wall sound as well.
‫All right.
‫Perfect.
‫So I would say we are done with this game.
‫Of course, there is plenty to do still.
‫We can still improve the game.
‫We could hand over the score to the game over scene.
‫We could give the capability of turning off or on the sound.
‫We could as well add an AI capability, and that's something that is a little challenge for you.
‫So add an AI for your player to wreck it.
‫All right.
‫So try to do that.
‫It's not super easy.
‫It will take quite some thinking.
‫You have to consider what does this record do?
‫Should it check where the ball is?
‫Maybe, and follow the coordinates of it?
‫Just a little hint.
‫All right, try that.
‫And other than that, of course, please go ahead and improve the game as you like and as you progress
‫with the course, you will see many things that you could implement into this game as well.
‫So please go ahead and do that and share whatever you have done with us.
‫We would really like to see what you can create out of what you have learned.
‫Great, so have fun.
‫In the next chapter.
‫Please try the challenge and see you in the next video.