1
00:00:03,980 --> 00:00:07,640
In this lecture, we're going to start adding some background music for our game.

2
00:00:07,640 --> 00:00:10,970
And the first step for this is to find some music for our game.

3
00:00:10,970 --> 00:00:16,760
So I've gone over to open game dot org, which is a fantastic resource for indie developers.

4
00:00:16,760 --> 00:00:23,420
And if we head up to browse and then down to music, we'll have a whole bunch of music that we can choose

5
00:00:23,420 --> 00:00:23,870
from.

6
00:00:24,080 --> 00:00:28,340
Now we can narrow down our search with the search parameters on the left here.

7
00:00:28,340 --> 00:00:32,659
So first of all, I'm going to narrow down my license to look for CC zero.

8
00:00:32,659 --> 00:00:37,190
So copyright free, we want some music as our art type.

9
00:00:37,190 --> 00:00:41,540
And if we have a rough idea of what sort of thing we're looking for, we may want to narrow down our

10
00:00:41,540 --> 00:00:44,300
search even further with themes and things like that.

11
00:00:44,300 --> 00:00:48,800
I actually got pretty lucky though, when I was listening through some of these tracks and in the very

12
00:00:48,800 --> 00:00:53,330
first one in Chip Tunes Action, I found some pretty cool music for my game.

13
00:00:53,330 --> 00:00:58,130
And the great thing about this site is that we can also preview our music before we download it.

14
00:00:58,340 --> 00:01:04,640
So we just hit the play button and we can hear our music and this sounds pretty epic for a space battle,

15
00:01:04,640 --> 00:01:10,250
so I'm going to go with that track and if we scroll down, we can select our files down here and we

16
00:01:10,250 --> 00:01:11,960
can download our zip file.

17
00:01:12,590 --> 00:01:16,250
Once we've downloaded that, we need to import it into our project.

18
00:01:16,250 --> 00:01:19,130
So I've dropped mine in the assets pack.

19
00:01:19,130 --> 00:01:24,740
So we've got our five action chip tunes in here and we can also preview them in Unity.

20
00:01:24,740 --> 00:01:29,930
So if we click on one of our tracks and go down to the preview window, if you don't see the preview

21
00:01:29,930 --> 00:01:32,930
window, it might be closed up down the bottom like it is here.

22
00:01:32,960 --> 00:01:35,030
All we need to do is just drag it up.

23
00:01:35,770 --> 00:01:37,720
Now we can go ahead and hit the play button.

24
00:01:40,540 --> 00:01:42,770
And here's one of those other tracks from that hack.

25
00:01:44,160 --> 00:01:49,560
Now, before we start adding this music to our game, I've noticed that our asset pack is starting to

26
00:01:49,560 --> 00:01:50,510
get a little bit messy.

27
00:01:50,520 --> 00:01:55,620
We've got some materials in there in various places, so let's do a quick bit of housekeeping.

28
00:01:55,860 --> 00:02:02,100
I'm going to right click and create a new folder for our backgrounds and we'll drag the star filled

29
00:02:02,100 --> 00:02:04,920
Star Zero and stars one into that.

30
00:02:05,220 --> 00:02:10,830
And then in the assets folder, I'm going to create a new folder specifically for our materials that

31
00:02:10,830 --> 00:02:11,880
we've been creating.

32
00:02:12,840 --> 00:02:17,970
So in here we had the background so we can drag that in.

33
00:02:18,210 --> 00:02:22,140
And in our space shooter folder we also had our M explosions.

34
00:02:22,140 --> 00:02:24,570
So let's drag that into the materials folder as well.

35
00:02:24,600 --> 00:02:29,070
That just makes them nice and easy to find and separates them away from the asset packs that we've been

36
00:02:29,070 --> 00:02:30,000
importing.

37
00:02:30,210 --> 00:02:32,100
So that's the housekeeping done.

38
00:02:32,100 --> 00:02:34,980
So now let's go over to our audio player and see what we did.

39
00:02:34,980 --> 00:02:36,030
Last Lecture.

40
00:02:36,150 --> 00:02:42,450
We created this audio player script, which held a audio clip to be played and specified the volume

41
00:02:42,450 --> 00:02:43,740
that we wanted to play it.

42
00:02:43,740 --> 00:02:50,520
And if we open up our audio player, then we were using this audio source play clip at point.

43
00:02:50,520 --> 00:02:53,550
But for our music, we don't really want this one shot audio.

44
00:02:53,550 --> 00:02:56,370
We want it to be continuously playing in the background.

45
00:02:56,370 --> 00:03:02,160
So let's get a better idea of how unity actually handles music in our game and understand what this

46
00:03:02,160 --> 00:03:04,290
audio source actually is.

47
00:03:04,740 --> 00:03:08,550
Well, the audio in Unity really comes in three parts.

48
00:03:08,550 --> 00:03:13,920
First of all, we need an audio listener, which is the thing that will allow us to hear the audio.

49
00:03:13,920 --> 00:03:18,540
And you may be wondering where that was sitting when we were doing this one shot audio and I'll show

50
00:03:18,540 --> 00:03:21,360
you where that is when we go back into Unity in a moment.

51
00:03:21,570 --> 00:03:25,290
Next, we need an audio source to play our audio.

52
00:03:25,290 --> 00:03:28,830
So that was that audio source play clip at point.

53
00:03:28,830 --> 00:03:32,280
And again, I'll show you where that was sitting with our one shot audio.

54
00:03:32,310 --> 00:03:34,440
And finally, we need an audio file.

55
00:03:34,440 --> 00:03:40,710
So the actual sound that gets played, so if we follow the arrows here, we have our audio file feeds

56
00:03:40,710 --> 00:03:46,650
into our audio source and our audio source gets listened to by our audio listener.

57
00:03:46,980 --> 00:03:52,110
So let's jump back into unity and I'm going to hit play and pause very quickly.

58
00:03:52,470 --> 00:03:57,870
And if we play to the point where we have our laser being instantiated, we'll see that we've got this

59
00:03:57,870 --> 00:03:59,430
one shot audio clip.

60
00:03:59,430 --> 00:04:05,520
And if we click on that one shot audio, we'll find our audio source without audio clip attached.

61
00:04:05,520 --> 00:04:11,280
So we were passing that audio clip from our audio player over to this audio source.

62
00:04:11,280 --> 00:04:15,690
And the listener for this audio source actually sits on our main camera.

63
00:04:15,690 --> 00:04:19,890
So if we look on our main camera, right near the bottom, we've got this audio listener.

64
00:04:19,890 --> 00:04:25,680
And that's why when we were playing our one shot audio, we were telling it to play at the camera position

65
00:04:25,680 --> 00:04:27,030
for the clearest sound.

66
00:04:27,030 --> 00:04:32,940
So if we come out of play mode and go back over to our audio player, let's have a think about how we're

67
00:04:32,940 --> 00:04:37,440
going to play our music well rather than mess with the audio player.

68
00:04:37,440 --> 00:04:42,000
For now, let's go ahead and add a new component to this game object.

69
00:04:42,000 --> 00:04:45,150
And the component we want is an audio source.

70
00:04:45,150 --> 00:04:50,040
Now, this audio source has a lot of bells and whistles and levers that we can pull.

71
00:04:50,040 --> 00:04:55,380
And it may be a little bit overwhelming unless you've done any audio engineering in the past, but for

72
00:04:55,380 --> 00:04:59,370
us we can actually ignore the vast majority of what's going on here.

73
00:04:59,370 --> 00:05:04,950
We're going to be playing two D sound, so everything in this three D sound setting can be completely

74
00:05:04,950 --> 00:05:05,460
ignored.

75
00:05:05,460 --> 00:05:06,900
So we'll just roll that up.

76
00:05:07,080 --> 00:05:12,150
And the only things we're interested in is our audio clip, which is the thing we want to play.

77
00:05:12,150 --> 00:05:15,300
So let's go over to our audio and drag the clip.

78
00:05:15,300 --> 00:05:17,460
We want into the audio clip.

79
00:05:17,580 --> 00:05:22,350
We don't need to worry about the output and we can see here that it's expecting an audio mixer.

80
00:05:22,350 --> 00:05:26,400
It's a bit overkill for our game though, so we really don't need to worry about that.

81
00:05:26,580 --> 00:05:30,150
We have a mute option so we can mute and unmute our audio.

82
00:05:30,150 --> 00:05:34,170
We don't need to worry about any of the bypass effects for our music.

83
00:05:34,170 --> 00:05:36,090
We will want it to play on Awake.

84
00:05:36,090 --> 00:05:38,940
So the moment the game starts, the music will start with it.

85
00:05:38,940 --> 00:05:43,980
But if we wanted to manually trigger our audio to play, then we could turn that off and then control

86
00:05:43,980 --> 00:05:45,000
that in code.

87
00:05:45,000 --> 00:05:50,430
And then finally for our checkboxes, we have a looping option and our music wants to be able to loop

88
00:05:50,430 --> 00:05:51,900
continuously through the game.

89
00:05:51,900 --> 00:05:55,320
So let's enable that and hopefully for your music that you found.

90
00:05:55,320 --> 00:05:56,730
It is a looping tracks.

91
00:05:56,730 --> 00:06:01,920
There won't be any hard cuts between the beginning and the end, then down onto our sliders.

92
00:06:01,920 --> 00:06:06,780
We don't need to worry about the priority or the pitch or the stereo plan or any of that stuff.

93
00:06:06,810 --> 00:06:09,420
The only thing we really care about is the volume.

94
00:06:09,420 --> 00:06:15,360
So that's our normal volume slider like we've added to our audio player and we could arguably pay attention

95
00:06:15,360 --> 00:06:17,730
to the spatial blend as well.

96
00:06:17,820 --> 00:06:21,510
As we can see, it goes from two D to three D.

97
00:06:21,510 --> 00:06:23,040
So what is that doing?

98
00:06:23,040 --> 00:06:28,620
Well, when we set it to two D, the audio listener isn't really going to care where the sound is originating

99
00:06:28,620 --> 00:06:34,320
from, but in three D it will affect how loudly we can hear that sound based on where we're viewing

100
00:06:34,320 --> 00:06:35,670
it from, from the camera.

101
00:06:35,670 --> 00:06:40,440
So if you think about three D games, if something's off in the distance, it's not going to be as loud

102
00:06:40,440 --> 00:06:42,180
as something that's right next to you.

103
00:06:42,180 --> 00:06:43,200
So not massive.

104
00:06:43,310 --> 00:06:44,660
Be relevant for our game.

105
00:06:44,660 --> 00:06:48,920
The only thing we really need to be aware of is that it should be set to two D.

106
00:06:49,430 --> 00:06:54,020
Now if we go ahead and hit play, we should find that audio source with Play on Awake.

107
00:06:54,020 --> 00:06:56,180
We'll start to play our music straight away.

108
00:06:56,630 --> 00:06:57,860
So let's hit play.

109
00:06:57,950 --> 00:07:01,160
And we do in fact get our music playing right out of the gate.

110
00:07:01,190 --> 00:07:04,700
And this has really drastically changed the feel of our game.

111
00:07:05,210 --> 00:07:10,370
For me, I think it makes the game feel a lot more exciting and as though we're going into battle against

112
00:07:10,370 --> 00:07:11,410
these invaders.

113
00:07:11,420 --> 00:07:15,120
So music selection is also incredibly important.

114
00:07:15,230 --> 00:07:19,160
So if we went with something more subdued, it would feel significantly different.

115
00:07:19,550 --> 00:07:23,210
So Music Choice is also a key part of your game design.

116
00:07:25,400 --> 00:07:28,730
So congratulations on adding music to your game.

117
00:07:28,970 --> 00:07:34,160
And with all of our sounds added, it's now time to start thinking about the user interface because

118
00:07:34,160 --> 00:07:39,680
our player can take damage, but we really have no idea of how much health we've got left or how many

119
00:07:39,680 --> 00:07:41,000
points we've been scoring.

120
00:07:41,300 --> 00:07:44,780
We'll start our journey into that in the next lecture, so I'll see you there.

