1
00:00:00,000 --> 00:00:03,540
Welcome back, my fellow game developers.

2
00:00:03,540 --> 00:00:06,740
In this video, we've added some sound effects.

3
00:00:06,735 --> 00:00:09,515
So when we run the game,

4
00:00:09,510 --> 00:00:13,390
you'll notice now that when we shoot,

5
00:00:14,360 --> 00:00:16,760
we have the bird sound.

6
00:00:16,755 --> 00:00:17,945
If we open the chest,

7
00:00:17,940 --> 00:00:19,960
we get a rifle.

8
00:00:22,550 --> 00:00:25,190
We have a different sound.

9
00:00:25,185 --> 00:00:29,165
And if we try to break this, there we go.

10
00:00:29,160 --> 00:00:32,430
You can see that we have a sound effect for that also.

11
00:00:32,430 --> 00:00:34,820
So let's not waste any more time,

12
00:00:34,815 --> 00:00:37,345
and let's get started.

13
00:00:37,345 --> 00:00:41,155
Okay, so now it's time to play

14
00:00:41,150 --> 00:00:42,920
some sound effects and make

15
00:00:42,920 --> 00:00:45,280
the game come alive even more.

16
00:00:45,275 --> 00:00:47,515
So what are we going to do?

17
00:00:47,510 --> 00:00:49,460
The first thing is obviously we need

18
00:00:49,460 --> 00:00:52,520
a reference to all of our sound effects.

19
00:00:52,520 --> 00:00:55,120
So in here I'm going to duplicate this.

20
00:00:55,115 --> 00:00:56,435
And instead of music,

21
00:00:56,435 --> 00:00:59,635
I'm going to call this the effects at Enter.

22
00:00:59,630 --> 00:01:01,250
Oops, not enter. There we go.

23
00:01:01,250 --> 00:01:04,000
So now we have a reference to the sound effects.

24
00:01:03,995 --> 00:01:05,795
But there is a problem.

25
00:01:05,795 --> 00:01:08,185
If I want to use the same method

26
00:01:08,180 --> 00:01:10,580
that I've used to play our music,

27
00:01:10,580 --> 00:01:12,620
then our sound effects are going

28
00:01:12,620 --> 00:01:14,650
to be replacing our music.

29
00:01:14,645 --> 00:01:16,145
And that's a no-no.

30
00:01:16,145 --> 00:01:18,875
We don't want the sound effects to replace music.

31
00:01:18,875 --> 00:01:21,535
That's just not while logical.

32
00:01:21,530 --> 00:01:24,490
So we have something different that we can do.

33
00:01:24,485 --> 00:01:28,615
And that is a method that is play clip at point.

34
00:01:28,610 --> 00:01:31,730
And I do recommend that you open the resources of

35
00:01:31,730 --> 00:01:33,380
the audio source and you look

36
00:01:33,380 --> 00:01:35,620
through everything you can find.

37
00:01:35,615 --> 00:01:37,925
So you can see you can change the play on awake,

38
00:01:37,925 --> 00:01:40,525
the pitch, the MUX using cold.

39
00:01:40,520 --> 00:01:43,640
And this is an entire course all by its own.

40
00:01:43,640 --> 00:01:46,670
If you want to go into the Audio Source,

41
00:01:46,670 --> 00:01:48,140
how to manipulate the music,

42
00:01:48,140 --> 00:01:50,570
how to manipulate different sound effects

43
00:01:50,570 --> 00:01:52,100
and all of that good stuff.

44
00:01:52,100 --> 00:01:55,310
But for now, let's focus on the play clip. At the point.

45
00:01:55,310 --> 00:01:56,720
This is how you call it.

46
00:01:56,720 --> 00:01:58,070
You need a position,

47
00:01:58,069 --> 00:02:00,519
a volume if you need to clip.

48
00:02:00,515 --> 00:02:02,035
And you can see in the description that

49
00:02:02,030 --> 00:02:03,530
it plays an audio clip

50
00:02:03,530 --> 00:02:06,670
at a given position in the world space.

51
00:02:06,665 --> 00:02:08,155
So this is what we need.

52
00:02:08,150 --> 00:02:10,190
But you can see right here that

53
00:02:10,190 --> 00:02:12,620
the position in world space,

54
00:02:12,620 --> 00:02:14,960
well, where do you think is

55
00:02:14,960 --> 00:02:18,640
the best position to play our music?

56
00:02:18,635 --> 00:02:20,395
Well, I'm going to tell you

57
00:02:20,390 --> 00:02:22,280
right now that the best place to

58
00:02:22,280 --> 00:02:26,120
play that is exactly on the main camera,

59
00:02:26,120 --> 00:02:28,030
exactly on the listener.

60
00:02:28,025 --> 00:02:30,575
So we can hear it the best way.

61
00:02:30,575 --> 00:02:32,875
Because I click on the 2D up here,

62
00:02:32,870 --> 00:02:35,380
we can see that we have this 3D.

63
00:02:35,375 --> 00:02:37,265
And on the audio listener,

64
00:02:37,265 --> 00:02:40,715
if I had to see how that works,

65
00:02:40,715 --> 00:02:42,605
how do I show you?

66
00:02:42,605 --> 00:02:44,545
Maybe on the Audio Manager,

67
00:02:44,540 --> 00:02:46,400
on some kind of, well,

68
00:02:46,400 --> 00:02:48,430
okay, for now, I'm not going to show you,

69
00:02:48,425 --> 00:02:50,245
or at least we can see this right here.

70
00:02:50,240 --> 00:02:54,470
So this is the range at which we play our music.

71
00:02:54,470 --> 00:02:57,710
And for now we are playing on the audio source that,

72
00:02:57,710 --> 00:02:59,230
so that is not bad.

73
00:02:59,225 --> 00:03:02,575
But if we play the clip off point and it's

74
00:03:02,570 --> 00:03:06,020
somewhere far away from the listener,

75
00:03:06,020 --> 00:03:08,210
we won't be able to hear it properly.

76
00:03:08,210 --> 00:03:09,920
So that's why we are going to play

77
00:03:09,920 --> 00:03:12,920
the sound on the main camera.

78
00:03:12,920 --> 00:03:14,260
Was that out of the way?

79
00:03:14,255 --> 00:03:17,015
Let's go back into our code right here.

80
00:03:17,015 --> 00:03:22,055
And we are going to go ahead and create a public void,

81
00:03:22,055 --> 00:03:25,535
play as a fax.

82
00:03:25,535 --> 00:03:28,615
And this time we're going to give it an integer which

83
00:03:28,610 --> 00:03:32,360
is the fax number.

84
00:03:32,360 --> 00:03:34,700
And in here I'm going to

85
00:03:34,700 --> 00:03:36,260
go ahead and open up the brackets.

86
00:03:36,260 --> 00:03:38,780
And I'm going to say that the audio source,

87
00:03:38,780 --> 00:03:43,090
dot play, clip, play,

88
00:03:43,085 --> 00:03:44,485
all know the actual,

89
00:03:44,480 --> 00:03:46,880
not the audio source that we have a reference to,

90
00:03:46,880 --> 00:03:51,110
but the actual audio source.

91
00:03:51,110 --> 00:03:52,580
So the one which has

92
00:03:52,580 --> 00:03:57,100
the a as capital that play clip at a point.

93
00:03:57,095 --> 00:03:59,485
And in here we are going to give it

94
00:03:59,480 --> 00:04:01,910
a sound effect or an audio clip,

95
00:04:01,910 --> 00:04:05,900
which is going to be the effects number.

96
00:04:05,900 --> 00:04:08,500
Okay, so save that.

97
00:04:08,495 --> 00:04:10,375
And what is the problem in here?

98
00:04:10,370 --> 00:04:11,720
Well, obviously we need to

99
00:04:11,720 --> 00:04:14,300
add the position and what's the position?

100
00:04:14,300 --> 00:04:15,440
It's the main camera.

101
00:04:15,440 --> 00:04:19,720
So remember that we can access the camera dot domain,

102
00:04:19,715 --> 00:04:23,155
dot transform the position.

103
00:04:23,150 --> 00:04:25,540
And honestly, I'm not sure if we've covered this.

104
00:04:25,535 --> 00:04:28,715
So I'm just going to tell you that if we write camera,

105
00:04:28,715 --> 00:04:30,235
that main, we immediately

106
00:04:30,230 --> 00:04:32,200
get a reference to the main camera.

107
00:04:32,195 --> 00:04:35,255
And from there we can use the transform that position.

108
00:04:35,255 --> 00:04:36,745
If we didn't cover this,

109
00:04:36,740 --> 00:04:37,910
I'm sorry, I said, Well,

110
00:04:37,910 --> 00:04:40,690
we already know, but maybe we already did.

111
00:04:40,685 --> 00:04:43,535
In any case, this is how we access the main camera.

112
00:04:43,535 --> 00:04:47,755
So now let's go ahead and try to break some boxes or not

113
00:04:47,750 --> 00:04:52,310
break the boxes actually tried to break the Roberta's.

114
00:04:52,310 --> 00:04:54,860
So back in our game,

115
00:04:54,860 --> 00:04:58,960
we can see that if we go to the breakable,

116
00:04:58,955 --> 00:05:04,645
so breakable, or is it the receivables?

117
00:05:04,640 --> 00:05:06,110
There we go In the breakable,

118
00:05:06,110 --> 00:05:07,960
if we are dashing,

119
00:05:07,955 --> 00:05:09,775
we said the trigger to break.

120
00:05:09,770 --> 00:05:11,690
So in here we can either immediately

121
00:05:11,690 --> 00:05:14,960
call or we can go ahead and create a method.

122
00:05:14,960 --> 00:05:16,520
And let's say for example,

123
00:05:16,520 --> 00:05:22,630
the method is going to be a public void.

124
00:05:22,625 --> 00:05:27,995
Play, break as affects.

125
00:05:27,995 --> 00:05:29,905
And in here if you want.

126
00:05:29,900 --> 00:05:32,510
Now, there is two different types

127
00:05:32,510 --> 00:05:35,050
of maybe thinking about this way.

128
00:05:35,045 --> 00:05:37,375
If you want, we can just have one

129
00:05:37,370 --> 00:05:39,740
breaking sound for all of our breakable.

130
00:05:39,740 --> 00:05:41,540
Or if you want, you can go

131
00:05:41,540 --> 00:05:43,510
ahead and create in here, for example,

132
00:05:43,505 --> 00:05:46,105
a public integer or not

133
00:05:46,100 --> 00:05:49,280
public actually I serialized field is something

134
00:05:49,280 --> 00:05:51,920
butter integer and it's going to be

135
00:05:51,920 --> 00:05:57,020
the ASA fax number to play, for example.

136
00:05:57,020 --> 00:05:58,760
And then you can choose which one you

137
00:05:58,760 --> 00:06:00,790
play and you can send it right here.

138
00:06:00,785 --> 00:06:07,705
So access the audio manager dot instance,

139
00:06:07,700 --> 00:06:17,640
dot play as effects and sent to the fax number to play.

140
00:06:17,770 --> 00:06:21,890
Close that. And then when we do break in here,

141
00:06:21,890 --> 00:06:23,570
after we trigger the animation,

142
00:06:23,570 --> 00:06:27,790
we can go ahead and play break as effects.

143
00:06:27,785 --> 00:06:29,875
And there we go.

144
00:06:29,870 --> 00:06:31,300
That's all that we need to do.

145
00:06:31,295 --> 00:06:32,665
Or if you want, there is

146
00:06:32,660 --> 00:06:35,030
a another way and that is playing

147
00:06:35,030 --> 00:06:39,920
the sound effects using the animation event if you want.

148
00:06:39,920 --> 00:06:45,140
So if we go in the bot towards the bot, no,

149
00:06:45,140 --> 00:06:49,220
bought, the breakable bought if we go to the animations,

150
00:06:49,220 --> 00:06:52,240
we can choose in here to have some kind of event system.

151
00:06:52,235 --> 00:06:54,285
For example, here we destroy,

152
00:06:54,289 --> 00:06:55,999
we can play this right here.

153
00:06:56,000 --> 00:06:58,280
So as soon as it breaks bam in here,

154
00:06:58,280 --> 00:07:01,030
we add this animation event.

155
00:07:01,025 --> 00:07:04,165
Maybe move it a little bit to the left.

156
00:07:04,160 --> 00:07:06,100
We play the animation event.

157
00:07:06,095 --> 00:07:08,225
We play the break as effects.

158
00:07:08,225 --> 00:07:11,275
And on the breakable bot will

159
00:07:11,270 --> 00:07:14,600
notice that we have the fax number that we want to play.

160
00:07:14,600 --> 00:07:17,570
And if we go to the audio manager,

161
00:07:17,570 --> 00:07:20,060
okay, so we have added the sound effects yet.

162
00:07:20,060 --> 00:07:23,030
So click in here all your sound effects,

163
00:07:23,030 --> 00:07:24,530
select all of these and

164
00:07:24,530 --> 00:07:26,750
drag them and to the sound effects.

165
00:07:26,750 --> 00:07:29,420
As you can see, we have 12 sound effects.

166
00:07:29,420 --> 00:07:31,160
One of them is the bottle breaks,

167
00:07:31,160 --> 00:07:32,870
so this is what we are going to be using.

168
00:07:32,870 --> 00:07:35,300
So let's hear that.

169
00:07:35,300 --> 00:07:38,200
Okay, So I think that's good enough.

170
00:07:38,195 --> 00:07:40,325
A bottle break as a outbreak.

171
00:07:40,325 --> 00:07:43,465
So what is the position on the Audio Manager?

172
00:07:43,460 --> 00:07:44,900
It's the 0.

173
00:07:44,900 --> 00:07:46,870
So I go to the breakable.

174
00:07:46,865 --> 00:07:50,035
I set it 0 exactly.

175
00:07:50,030 --> 00:07:51,460
So it was waiting for us.

176
00:07:51,455 --> 00:07:58,435
Excellent. And 0, save that. Run the game.

177
00:07:58,430 --> 00:08:00,870
And we should see,

178
00:08:02,740 --> 00:08:06,790
oops, there we go.

179
00:08:06,785 --> 00:08:11,675
And you can slightly here how that bought really broke.

180
00:08:11,675 --> 00:08:13,285
So with that out of the way,

181
00:08:13,280 --> 00:08:15,230
with all of these interesting ways

182
00:08:15,230 --> 00:08:17,060
that we can play sound effects.

183
00:08:17,060 --> 00:08:19,290
I'm going to issue you a challenge.

184
00:08:19,294 --> 00:08:22,674
And your challenge is to add all of the sound effects.

185
00:08:22,670 --> 00:08:26,000
So find all the sound effects you need for your games.

186
00:08:26,000 --> 00:08:28,130
All the shooting, the blood, the shotgun,

187
00:08:28,130 --> 00:08:31,990
the pistil, the gun, whatever you want,

188
00:08:31,985 --> 00:08:35,695
and call the method and all of the appropriate places

189
00:08:35,690 --> 00:08:39,610
and play the sound facts so well that out of the way,

190
00:08:39,605 --> 00:08:40,865
pause the video right now.

191
00:08:40,865 --> 00:08:42,745
I would not do all of these sound effects.

192
00:08:42,740 --> 00:08:46,960
I'm just going to a few and leave the rest to you.

193
00:08:46,955 --> 00:08:48,385
So with that out of the way,

194
00:08:48,380 --> 00:08:52,370
pause the video right now and go to the challenge.

195
00:08:52,370 --> 00:08:54,680
Oh, okay, welcome back.

196
00:08:54,680 --> 00:08:57,020
So what I'm going to do is I'm going to

197
00:08:57,020 --> 00:09:00,730
go into the weapons system.

198
00:09:00,725 --> 00:09:03,995
And in here I'm going to go ahead and

199
00:09:03,995 --> 00:09:07,595
create a serialized field,

200
00:09:07,595 --> 00:09:10,765
which is going to be int or integer.

201
00:09:10,760 --> 00:09:15,020
And whereas the breakable, breakable,

202
00:09:15,020 --> 00:09:18,950
I'm just going to use the same right here,

203
00:09:18,950 --> 00:09:22,150
same variable based on in here.

204
00:09:22,145 --> 00:09:25,415
And we're going to create a

205
00:09:25,415 --> 00:09:28,895
public or public whatever it is,

206
00:09:28,895 --> 00:09:30,715
we can make it private. It doesn't matter.

207
00:09:30,710 --> 00:09:36,720
Public void and play play.

208
00:09:37,540 --> 00:09:43,600
Weapon sound effects actually.

209
00:09:43,595 --> 00:09:46,075
And in here we are going to access the old

210
00:09:46,070 --> 00:09:51,290
your manager dot instance dot as effects.

211
00:09:51,290 --> 00:09:54,820
And we're going to send to it the fax number to play,

212
00:09:54,815 --> 00:09:57,025
save that back in Unity.

213
00:09:57,020 --> 00:10:00,350
Let's look at our audio manager and what we have.

214
00:10:00,350 --> 00:10:03,140
So AudioManager, let's see.

215
00:10:03,140 --> 00:10:07,300
The pistol will play the running rifle,

216
00:10:07,295 --> 00:10:09,175
pistol shot, which is four.

217
00:10:09,170 --> 00:10:13,390
So pistol as fax number for save that We can

218
00:10:13,385 --> 00:10:16,195
even maybe apply the changes

219
00:10:16,190 --> 00:10:18,880
to the pistol weapon and everything.

220
00:10:18,875 --> 00:10:20,755
Apply the changes.

221
00:10:20,750 --> 00:10:23,180
Now if I go into the Prefabs,

222
00:10:23,180 --> 00:10:27,230
if I go into the where are we?

223
00:10:27,230 --> 00:10:32,060
Weapons? Rifle, and let's see what we have in here.

224
00:10:32,060 --> 00:10:36,730
So I'm going to check the audio manager.

225
00:10:36,725 --> 00:10:39,695
The rifle sound is the seven.

226
00:10:39,695 --> 00:10:48,145
So seven, the shotgun sound is the shotgun.

227
00:10:48,140 --> 00:10:51,820
99.

228
00:10:51,815 --> 00:10:52,945
Save that.

229
00:10:52,940 --> 00:10:55,160
And I'm going to make our music

230
00:10:55,160 --> 00:10:57,430
just a little bit less noisy.

231
00:10:57,430 --> 00:11:02,560
So the volume, Let's set it to 0 to run the game.

232
00:11:02,560 --> 00:11:07,080
And now we should see that when we shoot with the pistol,

233
00:11:07,075 --> 00:11:10,765
we don't have any sound for some reason because obviously

234
00:11:10,765 --> 00:11:14,025
all obviously we forgot to even call it.

235
00:11:14,020 --> 00:11:16,300
So in here after we instantiate the bullet,

236
00:11:16,300 --> 00:11:21,910
also going to play the weapon as effects.

237
00:11:21,910 --> 00:11:25,890
There we go, save that back in our game.

238
00:11:25,885 --> 00:11:28,975
We run the game.

239
00:11:28,975 --> 00:11:34,495
And now when we How cool was that?

240
00:11:34,495 --> 00:11:37,215
So now we have an actual pistol being shot.

241
00:11:37,210 --> 00:11:40,070
Let's see what we get in here. The rifle.

242
00:11:47,200 --> 00:11:50,240
So you can see if we tried to shoot

243
00:11:50,240 --> 00:11:54,440
around because we are on the other side of the camera.

244
00:11:54,440 --> 00:11:57,450
So this is the main camera if we're on the right.

245
00:11:59,080 --> 00:12:02,150
The further we go away.

246
00:12:02,150 --> 00:12:05,090
This last weekend here the

247
00:12:05,090 --> 00:12:07,400
shots because we are playing at

248
00:12:07,400 --> 00:12:09,260
the main camera position and

249
00:12:09,260 --> 00:12:10,940
the main camera needs a bit of

250
00:12:10,940 --> 00:12:12,850
time to catch up with the player.

251
00:12:12,845 --> 00:12:14,165
So let's try this again.

252
00:12:14,165 --> 00:12:16,985
Maybe we get a shotgun this time.

253
00:12:24,310 --> 00:12:26,390
How cool is that?

254
00:12:26,390 --> 00:12:28,660
So now we have sounds for our guns.

255
00:12:28,655 --> 00:12:31,835
There is a lot more sound effects that you can add.

256
00:12:31,835 --> 00:12:33,715
I'm not going to add all of them.

257
00:12:33,710 --> 00:12:35,750
I'm just going to keep it as it is.

258
00:12:35,750 --> 00:12:37,580
But for now, let's go ahead and the

259
00:12:37,580 --> 00:12:39,710
Prefab, the Audio Manager.

260
00:12:39,710 --> 00:12:42,550
And let's just add it in here next to the player.

261
00:12:42,545 --> 00:12:45,985
Maybe we can even create a folder for it on its own.

262
00:12:45,980 --> 00:12:47,080
So I hope you enjoy it.

263
00:12:47,075 --> 00:12:49,205
I hope you are committing your changes.

264
00:12:49,205 --> 00:12:52,345
And I'll see you in the next video where we will be

265
00:12:52,340 --> 00:12:56,020
maybe adding some kind of audio mixer.

266
00:12:56,015 --> 00:12:58,175
So see you then.

