1 00:00:04,270 --> 00:00:05,210 ‫Welcome back. 2 00:00:05,230 --> 00:00:08,950 ‫And this video, we are going to add the sounds to our game. 3 00:00:08,950 --> 00:00:13,750 ‫And for example, you can find sounds on open game dot org. 4 00:00:13,750 --> 00:00:22,120 ‫And there I searched for example for sound effects and here I hear I left the licenses as they are. 5 00:00:22,150 --> 00:00:27,670 ‫If you want to know more about licenses, I would recommend to check out the license details on the 6 00:00:27,670 --> 00:00:28,270 ‫page. 7 00:00:28,270 --> 00:00:33,790 ‫So I search for ball and I found this ping pong or three ping pong sound a bit style. 8 00:00:34,870 --> 00:00:37,000 ‫And that's the sound that you could use. 9 00:00:37,000 --> 00:00:39,790 ‫For example, for the ball whenever it hit, it hits a wall. 10 00:00:39,790 --> 00:00:43,930 ‫And then you can simply generally check out the sounds that you like. 11 00:00:44,200 --> 00:00:49,510 ‫If you would like to use the exact same sound that we have in our project, you can download the project 12 00:00:49,510 --> 00:00:51,760 ‫and just use the sound assets. 13 00:00:52,330 --> 00:01:01,840 ‫All right, so let's go ahead and create a new folder and I'm going to call that one resources because 14 00:01:01,840 --> 00:01:05,950 ‫I want to drag everything except my scenes into my resources folder. 15 00:01:05,950 --> 00:01:13,630 ‫So I drag that one in there and do the same with the prefabs, the materials and the scripts. 16 00:01:14,890 --> 00:01:19,300 ‫Now what I will need to have is a new script onto my ball. 17 00:01:19,300 --> 00:01:24,130 ‫So let's go to the ball game object and create a new script here. 18 00:01:24,130 --> 00:01:30,520 ‫So use script and I'm going to call that one sound controller because that's what it does. 19 00:01:30,520 --> 00:01:34,030 ‫It controls the sound in here. 20 00:01:34,030 --> 00:01:36,220 ‫We only have one simple thing. 21 00:01:36,220 --> 00:01:42,100 ‫We need an audio source for our wall and we need an audio source for our record sound because these 22 00:01:42,100 --> 00:01:44,860 ‫are two different sounds that we are going to use. 23 00:01:45,610 --> 00:01:57,580 ‫And what I want to do is I simply create those two public audio source wall sound and public audio source 24 00:01:58,330 --> 00:02:00,010 ‫record sound. 25 00:02:01,210 --> 00:02:06,790 ‫Now, every time that there is a collision, I want to call one of those two sounds. 26 00:02:06,790 --> 00:02:10,180 ‫So I'm going to create a void on collision. 27 00:02:10,180 --> 00:02:12,520 ‫Enter to DX method in here. 28 00:02:12,790 --> 00:02:18,640 ‫So if the collision game object that name. 29 00:02:18,640 --> 00:02:32,140 ‫So the name of the game object that we collide with is equal to racket player one or is equal to record 30 00:02:32,140 --> 00:02:32,710 ‫player two. 31 00:02:32,710 --> 00:02:38,440 ‫So I'm just going to copy that and check out here Record Player two. 32 00:02:38,530 --> 00:02:42,790 ‫So if that's the collision, then please go ahead. 33 00:02:42,820 --> 00:02:45,850 ‫This dot record sound dot play. 34 00:02:46,420 --> 00:02:48,010 ‫So please play the sound. 35 00:02:48,850 --> 00:02:52,300 ‫And else it means that we hit a wall. 36 00:02:52,300 --> 00:02:53,770 ‫So please play the wall sound. 37 00:02:53,770 --> 00:02:58,390 ‫So this thought wall sound dot play 38 00:03:01,030 --> 00:03:01,750 ‫and that's it. 39 00:03:01,750 --> 00:03:03,340 ‫That's everything that we do in here. 40 00:03:03,340 --> 00:03:09,190 ‫So that's going to be our sound controller if we check out what the sound controller does here. 41 00:03:09,190 --> 00:03:16,720 ‫So as you can see, it expects after a little while, after it has loaded everything, it expects a 42 00:03:16,720 --> 00:03:20,980 ‫wall sound, which is an audio source and the record sound, which is an audio source. 43 00:03:21,010 --> 00:03:22,810 ‫Of course, we don't have them yet. 44 00:03:22,810 --> 00:03:29,830 ‫So you either, as I said, find them online and download them, or you just use the sounds that we 45 00:03:29,830 --> 00:03:30,460 ‫provide. 46 00:03:30,460 --> 00:03:34,240 ‫So create a new folder, call it sounds. 47 00:03:35,860 --> 00:03:38,050 ‫Now let's drag those sounds in there. 48 00:03:38,200 --> 00:03:44,080 ‫So I'm going to open up that folder and you can simply drag from the other project. 49 00:03:44,320 --> 00:03:50,440 ‫So we have the record sound and we have the wall sound, and now I would like to drag them just right 50 00:03:50,440 --> 00:03:56,140 ‫in there and I drag it over and as you can see, it doesn't apply it and that is because it expects 51 00:03:56,140 --> 00:03:57,490 ‫an audio source. 52 00:03:57,490 --> 00:04:01,240 ‫But those ones here are simply raw audio files. 53 00:04:01,240 --> 00:04:07,030 ‫So in order to get the audio sources, we need to create them in here. 54 00:04:07,030 --> 00:04:10,180 ‫So I create a new audio source onto my ball. 55 00:04:10,180 --> 00:04:13,900 ‫So right click on to the ball audio, audio source. 56 00:04:13,900 --> 00:04:21,130 ‫And the first one I'm going to call Racket Sound, and then I create the second one. 57 00:04:21,130 --> 00:04:30,040 ‫So create audio audio source and I'm going to call that wall sound and now we can drag those audio clips 58 00:04:30,040 --> 00:04:30,430 ‫in there. 59 00:04:30,430 --> 00:04:34,450 ‫So for the record sound, I'm going to drag that one just right in there. 60 00:04:35,530 --> 00:04:38,590 ‫And for my wall sound, that is the same thing. 61 00:04:38,590 --> 00:04:40,480 ‫So let's drag that in there. 62 00:04:42,620 --> 00:04:48,020 ‫Now the play on a I deactivate it, otherwise they will automatically play whenever we start the game. 63 00:04:48,020 --> 00:04:49,880 ‫And that's not something that I want. 64 00:04:50,870 --> 00:04:53,000 ‫You could, by the way, let's just check it out. 65 00:04:53,000 --> 00:04:54,800 ‫Record sound, let's activate it. 66 00:04:54,800 --> 00:04:55,700 ‫Let's play the game. 67 00:04:55,700 --> 00:04:57,110 ‫Let's see if the sound comes up. 68 00:04:57,710 --> 00:04:59,810 ‫And as you heard, the sound came up real quick. 69 00:04:59,810 --> 00:05:01,340 ‫So that's what Play on Awake does. 70 00:05:01,340 --> 00:05:02,600 ‫So I deactivate it. 71 00:05:02,630 --> 00:05:07,010 ‫If you activate loop, it will constantly run the sound all over, over and over again. 72 00:05:07,160 --> 00:05:09,740 ‫So now it won't because I didn't activate play on Awake. 73 00:05:09,740 --> 00:05:10,940 ‫So let's do both. 74 00:05:11,360 --> 00:05:16,400 ‫And you will see that it will automatically run this annoying sound. 75 00:05:16,400 --> 00:05:18,110 ‫So let's deactivate both of them. 76 00:05:18,410 --> 00:05:18,800 ‫Great. 77 00:05:18,800 --> 00:05:24,470 ‫So now let's drag those two, and I'm going to drag it up here so that I can drag it easier. 78 00:05:24,470 --> 00:05:26,570 ‫So let's drag the racket sound. 79 00:05:26,570 --> 00:05:30,260 ‫And as you can see, it moves over the inspector moves to the racket sound. 80 00:05:30,260 --> 00:05:37,370 ‫So if you want to still move it over and sometimes you just can't get it done because accidentally the 81 00:05:37,370 --> 00:05:39,710 ‫game object that is in the inspector changes. 82 00:05:39,710 --> 00:05:42,410 ‫You can simply lock it here at the top right side. 83 00:05:42,410 --> 00:05:44,480 ‫So here there's this little button. 84 00:05:44,690 --> 00:05:49,760 ‫Now it's locked and now I can drag the racket sound in here. 85 00:05:50,150 --> 00:05:52,310 ‫Actually, I dragged it into the wrong one. 86 00:05:52,310 --> 00:05:53,300 ‫Let's drag it in there. 87 00:05:53,300 --> 00:05:56,570 ‫And now let's drag the wall sound into there as well. 88 00:05:57,140 --> 00:06:03,740 ‫All right, now let's unlock the inspector and let's check our game if the sound works right. 89 00:06:11,070 --> 00:06:15,870 ‫They are our record sound and we have the wall sound as well. 90 00:06:18,890 --> 00:06:19,340 ‫All right. 91 00:06:19,340 --> 00:06:20,060 ‫Perfect. 92 00:06:20,450 --> 00:06:23,520 ‫So I would say we are done with this game. 93 00:06:23,540 --> 00:06:25,670 ‫Of course, there is plenty to do still. 94 00:06:25,670 --> 00:06:27,830 ‫We can still improve the game. 95 00:06:27,830 --> 00:06:31,220 ‫We could hand over the score to the game over scene. 96 00:06:31,220 --> 00:06:35,360 ‫We could give the capability of turning off or on the sound. 97 00:06:35,420 --> 00:06:42,080 ‫We could as well add an AI capability, and that's something that is a little challenge for you. 98 00:06:42,080 --> 00:06:46,550 ‫So add an AI for your player to wreck it. 99 00:06:47,240 --> 00:06:47,660 ‫All right. 100 00:06:47,660 --> 00:06:49,280 ‫So try to do that. 101 00:06:49,280 --> 00:06:50,240 ‫It's not super easy. 102 00:06:50,240 --> 00:06:52,250 ‫It will take quite some thinking. 103 00:06:52,250 --> 00:06:55,970 ‫You have to consider what does this record do? 104 00:06:56,000 --> 00:06:57,740 ‫Should it check where the ball is? 105 00:06:57,740 --> 00:07:00,050 ‫Maybe, and follow the coordinates of it? 106 00:07:00,050 --> 00:07:01,070 ‫Just a little hint. 107 00:07:01,220 --> 00:07:02,480 ‫All right, try that. 108 00:07:02,480 --> 00:07:08,300 ‫And other than that, of course, please go ahead and improve the game as you like and as you progress 109 00:07:08,300 --> 00:07:13,220 ‫with the course, you will see many things that you could implement into this game as well. 110 00:07:13,220 --> 00:07:16,610 ‫So please go ahead and do that and share whatever you have done with us. 111 00:07:16,610 --> 00:07:20,600 ‫We would really like to see what you can create out of what you have learned. 112 00:07:20,780 --> 00:07:22,250 ‫Great, so have fun. 113 00:07:22,250 --> 00:07:23,360 ‫In the next chapter. 114 00:07:23,360 --> 00:07:26,630 ‫Please try the challenge and see you in the next video.