1
00:00:02,940 --> 00:00:06,880
In this lecture, we're going to add some sound effects so that when the player touches the coin, it

2
00:00:06,880 --> 00:00:07,840
goes diddling.

3
00:00:07,840 --> 00:00:10,500
And you know that you've picked up the coin.

4
00:00:10,510 --> 00:00:14,950
I've given you a sound effect that I made myself in audacity for this particular lecture.

5
00:00:14,950 --> 00:00:19,660
You can download that against this lecture, and I've got a challenge for you right from the get go,

6
00:00:19,660 --> 00:00:23,950
and that is to use play clip at point to play a sound effect when you pick up the coin.

7
00:00:23,950 --> 00:00:28,630
Now, I'm going to be using a very, very simple implementation for this approach.

8
00:00:28,630 --> 00:00:30,580
There's more complicated ways of doing this.

9
00:00:30,580 --> 00:00:35,410
In previous sections of the course, we've made a an audio manager that has all of our different sound

10
00:00:35,410 --> 00:00:38,740
effects in it, and then we call publicly from other classes.

11
00:00:38,740 --> 00:00:44,260
What I'm going to do is just the very quick and dirty, simple, putting the play clip at point, actually

12
00:00:44,260 --> 00:00:49,000
within our coin pick up script so that we can quickly have some sound effect playing.

13
00:00:49,000 --> 00:00:54,340
You can do it either of those two ways if you want to try the more, I guess, proper way of doing things.

14
00:00:54,340 --> 00:00:58,540
And you can set up an audio controller that has all of the different sound effects being fed into it.

15
00:00:58,540 --> 00:01:01,930
Or you can just do the quick and dirty way, which is what I'll be doing as well.

16
00:01:01,930 --> 00:01:05,410
But it's good to see different ways of doing things, so then you can make your own opinion on these

17
00:01:05,410 --> 00:01:05,620
things.

18
00:01:05,620 --> 00:01:06,700
So there's a challenge.

19
00:01:06,700 --> 00:01:07,390
Positive video.

20
00:01:07,420 --> 00:01:09,160
See you back here when you've given it a go.

21
00:01:11,560 --> 00:01:12,790
First step in the process.

22
00:01:12,790 --> 00:01:16,150
I need a new folder which is right click Create Folder.

23
00:01:16,150 --> 00:01:19,930
I'll call this audio within audio double click to open that up.

24
00:01:19,930 --> 00:01:26,440
I'm going to drag in my sound effects coin pickup and it sounds something like now back into my script,

25
00:01:26,440 --> 00:01:27,460
so I'm going to do this quick way.

26
00:01:27,460 --> 00:01:29,200
You've got a couple of different ways to play sound.

27
00:01:29,200 --> 00:01:34,270
You can just say play sound, but because when we're triggering, when the coin is being bumped into

28
00:01:34,270 --> 00:01:36,430
by the player, we're destroying it straight away.

29
00:01:36,430 --> 00:01:38,320
So we need something that sticks around.

30
00:01:38,320 --> 00:01:41,890
That's why we're using play clip at point as opposed to just play.

31
00:01:41,890 --> 00:01:48,430
If you have just play something in here like some sort of SFX Dot play, obviously we'd write the code

32
00:01:48,430 --> 00:01:49,360
more properly than that.

33
00:01:49,360 --> 00:01:53,500
But if you're just using play, then at the moment it starts to play.

34
00:01:53,500 --> 00:01:58,450
It's also destroying itself and that sound goes away along with the audio source and all the other things

35
00:01:58,450 --> 00:02:00,550
that are living on the game object.

36
00:02:00,550 --> 00:02:04,990
Which reminds me, let's go over to our coin prefab prefabs coin.

37
00:02:04,990 --> 00:02:09,520
In addition to these other things, we need to have an audio source so we have something that can actually

38
00:02:09,520 --> 00:02:11,050
be playing these things.

39
00:02:11,050 --> 00:02:13,000
We want it to play within audio source.

40
00:02:13,000 --> 00:02:15,280
We've got some settings in there that we've played around with before.

41
00:02:15,310 --> 00:02:16,030
Play on Awake.

42
00:02:16,030 --> 00:02:17,140
We'll turn that off now.

43
00:02:17,140 --> 00:02:23,140
Within my coin pick up class, I'm going to Serialize Field and I'll create an audio clip.

44
00:02:23,650 --> 00:02:26,470
That's the thing we're going to play and I'll call it Coin.

45
00:02:27,760 --> 00:02:30,600
Pick up as f x semicolon.

46
00:02:30,610 --> 00:02:35,720
Now I'm going to jump down into my on trigger just above destroying in here.

47
00:02:35,740 --> 00:02:41,590
Now we want to be accessing audio source and as we've talked about, play clip at point y play clip

48
00:02:41,590 --> 00:02:46,900
at point well that instantiate the audio so that when we destroy this object, it will still stick around.

49
00:02:46,900 --> 00:02:47,800
What are we playing?

50
00:02:47,800 --> 00:02:52,390
We're going to play the coin pick up SFX and where are we going to play that?

51
00:02:52,390 --> 00:02:56,800
We're going to play it at the position of the camera y the position of the camera.

52
00:02:56,800 --> 00:03:03,850
Well, if we just jump quickly into 3D view, you can see in here that the coin play clip a point,

53
00:03:03,850 --> 00:03:06,400
you can see my little sound thingy on it there.

54
00:03:06,400 --> 00:03:09,010
It's pretty small, so it'll play it right there in 3D space.

55
00:03:09,010 --> 00:03:10,440
However, the camera is over here.

56
00:03:10,460 --> 00:03:12,100
The camera is the thing that's listening.

57
00:03:12,100 --> 00:03:14,950
That's our headset or that's our headphones, if you will.

58
00:03:14,960 --> 00:03:18,580
If we're running around in a3d game, it's kind of nice to have a sound over there.

59
00:03:18,580 --> 00:03:22,600
Sound to the right and a sound over there, sound on the left or a distant or closer.

60
00:03:22,600 --> 00:03:23,590
That's a good thing to do.

61
00:03:23,590 --> 00:03:28,450
But in a2d game, we want to have the sound play the same no matter where it is on the screen.

62
00:03:28,450 --> 00:03:29,500
Well, that's what I want anyway.

63
00:03:29,500 --> 00:03:33,700
So we need to say play the sound right at where the camera is.

64
00:03:33,700 --> 00:03:42,550
The way we do that is by accessing camera dot main because it's the main camera and it's transform dot

65
00:03:42,550 --> 00:03:43,450
position.

66
00:03:43,450 --> 00:03:49,690
We can also add in here if we wanted to add a third parameter, we can add in the volume and that's

67
00:03:49,690 --> 00:03:50,500
a flute.

68
00:03:50,500 --> 00:03:55,540
So I could say if I don't want the coin to be too loud, I could add in here a lower volume.

69
00:03:55,570 --> 00:03:56,750
I can leave that where it is for now.

70
00:03:56,770 --> 00:04:01,540
Don't worry about putting the volume in it because I can adjust the volume over here on the actual game

71
00:04:01,540 --> 00:04:03,760
object itself so I could drag the volume down.

72
00:04:03,760 --> 00:04:05,800
So I'm not going to worry about doing it in code.

73
00:04:05,800 --> 00:04:07,780
This is a fairly quick implementation.

74
00:04:07,780 --> 00:04:12,490
Why am I not going through a bigger, more detailed implementation where we have an audio manager that's

75
00:04:12,490 --> 00:04:13,870
got all the different sound effects in it?

76
00:04:13,870 --> 00:04:16,420
Well, at this stage I've only got one sound effect in my game.

77
00:04:16,420 --> 00:04:17,769
That's all I want to implement.

78
00:04:17,769 --> 00:04:22,510
And I want to do this in a way so you can see if you're prototyping something, if you're messing around

79
00:04:22,510 --> 00:04:27,850
with it, if you want quick results, you don't have to go and implement the big proper full super architected

80
00:04:27,850 --> 00:04:28,210
approach.

81
00:04:28,210 --> 00:04:30,850
You can just say quickly bump play clip at point.

82
00:04:30,850 --> 00:04:32,560
That means it won't be destroyed.

83
00:04:32,560 --> 00:04:39,460
And if we click on Save jump back over into Unity, then we can decide what the sound effect is by clicking

84
00:04:39,460 --> 00:04:44,680
on our coin prefab and then scrolling around to see where the coin pick up sound effects is.

85
00:04:44,680 --> 00:04:47,110
And that's going to come from our audio folder.

86
00:04:47,110 --> 00:04:50,290
Drag that on in, and that is the sound effect we're going to use.

87
00:04:50,290 --> 00:04:53,920
So that for me is one of the simplest ways to get sound effects into your game that stick around.

88
00:04:53,920 --> 00:04:57,100
Nice and simple, let's click on place if it's actually worked.

89
00:04:58,000 --> 00:05:00,820
But then there we go.

90
00:05:00,850 --> 00:05:04,810
So just some very simple sound effects to get us going along that road to get a little bit of audio

91
00:05:04,810 --> 00:05:05,680
into our game.

92
00:05:05,680 --> 00:05:07,750
You can go and add some other sound effects if you want.

93
00:05:07,750 --> 00:05:11,830
For when the bullet hits the wall, the bullet hits an enemy or the bullet hits other things.

94
00:05:11,830 --> 00:05:16,420
And as I've said a couple of times in this lecture, if you want to do a more full implementation,

95
00:05:16,420 --> 00:05:21,070
then create yourselves an audio manager, as we've done in other sections of the course, and you can

96
00:05:21,070 --> 00:05:23,710
go about getting more structure to it.

97
00:05:23,710 --> 00:05:27,760
But for now, I just wanted to do a quick sound effect and to move on to the next part of what we're

98
00:05:27,760 --> 00:05:28,540
doing in our game.

99
00:05:28,540 --> 00:05:29,200
So good stuff.

100
00:05:29,200 --> 00:05:30,280
I'll see you in the next lecture.

