1
00:00:03,780 --> 00:00:08,670
In this lecture, we're going to set up our Laser Defender project and also do a little bit of messing

2
00:00:08,670 --> 00:00:10,590
around with the unity editor.

3
00:00:10,590 --> 00:00:16,620
Because as you can see here, I'm currently in a Unity 3D scene, and that is because when I created

4
00:00:16,620 --> 00:00:22,170
this project, I accidentally on purpose clicked on the 3D preset instead of 2D.

5
00:00:22,170 --> 00:00:28,260
And the reason I did this is to show you how to get from the 3D state into the 2D state if you don't

6
00:00:28,260 --> 00:00:31,200
automatically set 2D when you create your project.

7
00:00:31,230 --> 00:00:36,510
Now, to save you some time, you are probably going to be better off just starting up a new project

8
00:00:36,510 --> 00:00:39,150
and remembering to set that 2D option.

9
00:00:39,150 --> 00:00:44,040
But if you are in a 3D project, then let me walk you through some of the set up we're going to have

10
00:00:44,040 --> 00:00:49,290
to do and some of the pitfalls and challenges we're going to face later on in development.

11
00:00:49,620 --> 00:00:56,940
So the first step to setting up our project to act like a 2D project is to go over into the hierarchy.

12
00:00:56,940 --> 00:01:02,100
And rather than just having a main camera, we've now also got a directional light.

13
00:01:02,100 --> 00:01:06,780
We're not going to need this for a 2D game, so we can just really go ahead and delete it.

14
00:01:06,960 --> 00:01:09,690
This will leave us with just our main camera.

15
00:01:09,690 --> 00:01:12,750
And in here this is set up for 3D as well.

16
00:01:12,750 --> 00:01:19,020
So over on our camera component, the first thing we probably want to do is change our projection mode

17
00:01:19,020 --> 00:01:21,900
from perspective to orthographic.

18
00:01:22,140 --> 00:01:29,280
Finally, we want to remove our skybox and just have a flat background so we can change our clear flags

19
00:01:29,280 --> 00:01:31,890
from skybox to solid color.

20
00:01:31,890 --> 00:01:35,340
But in our same view, we can still see the skybox.

21
00:01:35,340 --> 00:01:42,000
So let's have a look at how we get rid of all of this and just work with a plain flat background up

22
00:01:42,000 --> 00:01:43,470
at the top of our same view.

23
00:01:43,470 --> 00:01:49,830
We have a whole bunch of options and to get rid of the skybox, we want this little stacked icon with

24
00:01:49,830 --> 00:01:56,520
the plus sign above it and we can either disable all of that entirely or in the dropdown we have a whole

25
00:01:56,520 --> 00:02:01,500
bunch of options where we can select whether we can see our post-processing, our particle effects and

26
00:02:01,500 --> 00:02:02,400
things like that.

27
00:02:02,930 --> 00:02:06,590
We will be using particle systems, so let's leave that on.

28
00:02:06,740 --> 00:02:10,690
But instead switch off our skybox, our fog.

29
00:02:10,699 --> 00:02:15,020
And since we're not going to need it, we might as well turn off our flares as well.

30
00:02:15,380 --> 00:02:19,490
Finally, up in this top bar, we also have this two D button.

31
00:02:19,490 --> 00:02:24,710
And if we click on this, it will change our camera and put us into a 2D flat view.

32
00:02:24,890 --> 00:02:29,150
Now, back in previous versions of Unity, this is pretty much all you'd really have to do.

33
00:02:29,180 --> 00:02:34,910
However, in the more recent versions of Unity, all of the 2D assets and packages have all been wrapped

34
00:02:34,910 --> 00:02:37,280
up separately to the 3D environment.

35
00:02:37,280 --> 00:02:42,800
So if we were to say go ahead and right click on our hierarchy, we'll see that we've got 3D objects,

36
00:02:42,800 --> 00:02:47,000
but we don't have any 2D objects, so we can't add any sprites to the game.

37
00:02:47,180 --> 00:02:53,030
Now to fix this, it's just a case of coming up to our window and then down to our package manager.

38
00:02:53,840 --> 00:02:58,880
And if we go ahead and select the unity registry right at the very top, we'll have a load of two D

39
00:02:58,880 --> 00:03:00,620
packages that we can choose from.

40
00:03:00,650 --> 00:03:05,690
Now, if you've set your project up as 2D already, you'll notice that pretty much all of these are

41
00:03:05,690 --> 00:03:06,870
already installed.

42
00:03:06,890 --> 00:03:10,190
The only one missing will be the 2D tile map extras.

43
00:03:10,670 --> 00:03:15,470
At its most basic, the only one you really, really need is the 2D sprites.

44
00:03:15,470 --> 00:03:17,690
So let's go ahead and install that first.

45
00:03:18,760 --> 00:03:23,080
And once that's installed, if we go ahead and right click on the hierarchy now, we'll see that we

46
00:03:23,080 --> 00:03:27,280
have our 2D objects so we can now add the sprites to our scene.

47
00:03:28,130 --> 00:03:31,640
And we're not really going to be using any of these other 2D options.

48
00:03:31,640 --> 00:03:37,340
But if you want to go ahead and sell these anyway and then your project will be in exactly the same

49
00:03:37,340 --> 00:03:41,930
state as it would have been had you selected the 2D option when creating the project.

50
00:03:42,470 --> 00:03:46,940
Now, while we're in the package manager, we may as well go ahead and set up the other packages we're

51
00:03:46,940 --> 00:03:50,360
going to need for our project as well to get that out of the way.

52
00:03:50,390 --> 00:03:54,740
So let's go down and double check that we've got our Tex mesh pro installed.

53
00:03:54,740 --> 00:04:01,430
And the last package we're going to need if we scroll up is going to be the input system, because for

54
00:04:01,430 --> 00:04:06,230
this project we're not going to be using the old inbuilt input system with unity.

55
00:04:06,230 --> 00:04:09,470
We're going to be using their new fancy input system.

56
00:04:09,740 --> 00:04:12,380
So let's go ahead and install that as well.

57
00:04:15,320 --> 00:04:20,720
Now during this install process, you will be presented with this warning message and this will ask

58
00:04:20,720 --> 00:04:25,910
you if you want to restart the editor and disable the old unity engine inputs.

59
00:04:26,180 --> 00:04:27,470
So let's go ahead and click.

60
00:04:27,470 --> 00:04:27,800
Yes.

61
00:04:27,800 --> 00:04:31,850
And this will finish off the installation process and then restart unity.

62
00:04:32,700 --> 00:04:36,930
And this might take some time to just re-import everything and reload the editor.

63
00:04:37,230 --> 00:04:41,940
So once the editor has reloaded, let's go ahead and close the package manager.

64
00:04:41,950 --> 00:04:45,970
And don't worry too much about that input system that we've just brought into our project.

65
00:04:45,990 --> 00:04:50,130
We'll get there and we'll look at it in a lot more detail when we start moving our player around the

66
00:04:50,130 --> 00:04:50,670
level.

67
00:04:50,850 --> 00:04:57,270
Now, the next thing I want to show you in here is how to change your editor around and save new layouts.

68
00:04:57,570 --> 00:05:02,100
Because when I'm working on a project, I'm not actually a massive fan of having my hierarchy over on

69
00:05:02,100 --> 00:05:06,660
this side of the screen, because a lot of the time I need to access something in the hierarchy and

70
00:05:06,660 --> 00:05:12,800
then do something in the inspector, and we can move and rearrange all these elements on our screen.

71
00:05:12,810 --> 00:05:17,730
If we click on the tab at the top that says hierarchy and then just click and drag.

72
00:05:17,730 --> 00:05:23,370
So left click and move it around, we'll see that we can move it around to different areas of the screen.

73
00:05:23,790 --> 00:05:28,050
So I'm going to drag it to the right of my scene view and snap it into place.

74
00:05:28,380 --> 00:05:34,860
And for this particular game, I'm also going to take the game window and just snap it to the left of

75
00:05:34,860 --> 00:05:38,910
my scene view so I can see my game and my scene in the same view.

76
00:05:39,360 --> 00:05:44,430
Now you can continue to drag and drop different areas of your screen and set up your editor however

77
00:05:44,430 --> 00:05:45,190
you like.

78
00:05:45,210 --> 00:05:49,920
Once you're done, if you go up to the top right dropdown where it says layout.

79
00:05:50,040 --> 00:05:53,220
We can go down and save our new layout here.

80
00:05:53,220 --> 00:05:56,560
We can give it a new name and we can really name it whatever we like.

81
00:05:56,580 --> 00:06:02,220
I'm just going to call mine the laser defender layout or lrd layout and hit save.

82
00:06:02,430 --> 00:06:07,400
And now if we click on our layout dropdown again, we'll see that we've got our LD layout in our list.

83
00:06:07,410 --> 00:06:11,040
So if we want to go back to default, we can click on our default option.

84
00:06:11,310 --> 00:06:15,300
And if we want to go to our laser defender layout that we've created, we can click on that.

85
00:06:15,880 --> 00:06:16,260
Okay.

86
00:06:16,260 --> 00:06:20,520
So with our layout now set up, I'm actually just going to open this up a little bit more so we can

87
00:06:20,520 --> 00:06:22,470
see some of the other options that we've got here.

88
00:06:22,470 --> 00:06:25,320
So we can always resize and move however we like.

89
00:06:25,590 --> 00:06:30,630
But for now, the only one I really want to see is this free aspect dropdown, and that's because we're

90
00:06:30,630 --> 00:06:33,540
going to change our aspect ratio for our game.

91
00:06:33,570 --> 00:06:40,200
Our space shooter is going to be somewhat mobile friendly, so I'm going to go with a nine by 16 aspect

92
00:06:40,200 --> 00:06:40,890
ratio.

93
00:06:41,550 --> 00:06:46,620
I've already got a pre created one in my list here, but if you don't have that, then you can just

94
00:06:46,620 --> 00:06:49,410
click on the plus button, give it a name.

95
00:06:49,410 --> 00:06:56,580
So nine by 16, change the type to aspect ratio and then just specify the width and height that you

96
00:06:56,580 --> 00:06:56,910
want.

97
00:06:56,910 --> 00:07:00,420
So in this case, it'll be nine on the X and 16 on the Y.

98
00:07:01,930 --> 00:07:07,300
Then if we go ahead and click on our nine by 16, we can kind of see why this layout is nice for our

99
00:07:07,300 --> 00:07:12,100
game, because we can hide our game window all the way to the side here and still see everything that's

100
00:07:12,100 --> 00:07:17,740
going to be going on on screen, but then have a nice large workspace for working in the scene itself.

101
00:07:18,330 --> 00:07:23,580
Next for our product set up, we're going to need some assets and that is going to be your challenge.

102
00:07:23,730 --> 00:07:29,910
So I want you to find some suitable assets for your game and then I want you to create a prefab for

103
00:07:29,910 --> 00:07:33,030
your player, a prefab for your first enemy.

104
00:07:33,150 --> 00:07:35,790
And I also want you to add a background to your scene.

105
00:07:35,970 --> 00:07:38,700
So you pause the video now and get that set up.

106
00:07:43,780 --> 00:07:44,200
Okay.

107
00:07:44,200 --> 00:07:45,010
Welcome back.

108
00:07:45,040 --> 00:07:48,570
So hopefully you found some assets for your project and for mine.

109
00:07:48,580 --> 00:07:51,570
I'm going to be using some that are available from Kenny.

110
00:07:51,580 --> 00:07:56,320
And if you've never heard of Kenny before, then he's a very generous and prolific game developer who

111
00:07:56,320 --> 00:07:59,640
offers a lot of assets on his website completely for free.

112
00:07:59,650 --> 00:08:05,710
So if we go up to the assets, you'll see that there's a whole bunch here available all under the CC

113
00:08:05,710 --> 00:08:10,270
zero license, meaning you can use them for both personal and commercial projects.

114
00:08:10,270 --> 00:08:15,730
And the first one I'm going to be looking for on Kenny's website is called Space Shooter Redux.

115
00:08:16,780 --> 00:08:22,270
So let's search for space shooter and it's this top one here and then we can go ahead and download.

116
00:08:22,510 --> 00:08:27,490
Now, even though these packs are completely free of charge, if you do have the resources, then do

117
00:08:27,490 --> 00:08:33,010
consider donating to Kenny so that he can continue to do this great work of providing free and open

118
00:08:33,010 --> 00:08:35,650
source assets for us aspiring game developers.

119
00:08:36,010 --> 00:08:41,530
And once that's finished downloading, we'll bring that into our project in Unity and back over in Unity,

120
00:08:41,530 --> 00:08:47,530
I've put mine in its own folder called Asset Packs and we've got our space shooter assets.

121
00:08:47,740 --> 00:08:54,130
So in here if we go into the PNG folder, we're going to need a player ship and we're also going to

122
00:08:54,130 --> 00:08:55,930
look for our first enemy.

123
00:08:56,140 --> 00:09:01,450
This is where we're going to run into another problem, if we started off in a3d scene, because if

124
00:09:01,450 --> 00:09:07,210
we select one of our sprites, we'll see that the texture type has come in as default.

125
00:09:07,210 --> 00:09:12,070
And if you're in a 2D project, which hopefully you are, you'll see that this by default is set to

126
00:09:12,070 --> 00:09:12,880
Sprite.

127
00:09:12,970 --> 00:09:19,030
This means for every image that we ever import into our 3D project that we want to use for 2D, we're

128
00:09:19,030 --> 00:09:24,460
going to have to change the texture type in the dropdown to Sprite 2D in UI.

129
00:09:24,880 --> 00:09:29,440
Then once we've set this, we'll notice a few changes have been made and then right at the bottom we're

130
00:09:29,440 --> 00:09:30,670
going to have to apply.

131
00:09:30,700 --> 00:09:36,880
Now, luckily, we can do a lot of them in one hit so we can highlight the whole bunch and then change

132
00:09:36,880 --> 00:09:38,980
all of them to sprites and apply.

133
00:09:39,250 --> 00:09:44,260
Once we've gone and done that, we can then use all of these images as regular sprites like we would

134
00:09:44,260 --> 00:09:46,390
do in a regular 2D project.

135
00:09:46,510 --> 00:09:48,670
Now back to setting up our player.

136
00:09:48,670 --> 00:09:53,260
Let's right click in the hierarchy and create a new empty object called player.

137
00:09:53,950 --> 00:09:59,410
Let's reset the transform for now and then choose one of the available player ships.

138
00:09:59,410 --> 00:10:05,380
I'm going to go with this blue one with the nice swept wing and I'm going to drag and drop that underneath

139
00:10:05,380 --> 00:10:08,440
the player with our base player set up.

140
00:10:08,440 --> 00:10:09,820
Let's go ahead and prefab them.

141
00:10:09,820 --> 00:10:16,270
So back up in the top level of the assets folder, let's right click and create a folder for our prefabs

142
00:10:17,410 --> 00:10:20,350
and we'll go ahead and drag and drop that into that folder.

143
00:10:20,860 --> 00:10:22,780
Next, we're going to want an enemy.

144
00:10:23,020 --> 00:10:28,270
So let's right click in our hierarchy, create a new empty game object and reset the transform.

145
00:10:29,130 --> 00:10:35,760
Let's call this Object Enemy Zero because we may create more enemies later on, and as programmers we

146
00:10:35,760 --> 00:10:38,760
start counting at zero under our enemy.

147
00:10:38,760 --> 00:10:41,190
Let's find a sprite to attach to them.

148
00:10:43,340 --> 00:10:47,210
I'm going to go with this little red one here.

149
00:10:47,840 --> 00:10:51,590
And once again, let's go ahead and drag that into our prefabs folder.

150
00:10:52,750 --> 00:10:57,310
Now, if we have a look over on our game screen, we've got both of them occupying the same space at

151
00:10:57,310 --> 00:10:57,820
the moment.

152
00:10:57,820 --> 00:11:00,250
So we'll move them around in just a moment.

153
00:11:00,250 --> 00:11:05,350
But first of all, we want to consider the size of these objects on our game screen.

154
00:11:05,350 --> 00:11:08,470
And I think these are just a little bit too big at the moment.

155
00:11:08,470 --> 00:11:14,530
So if we click on our main camera and then in our camera object, let's look at the size.

156
00:11:14,530 --> 00:11:20,200
And if we increase the size, we'll notice that we zoom out from our game.

157
00:11:20,560 --> 00:11:24,490
And if we decrease the size of our camera, we're going to zoom in.

158
00:11:25,150 --> 00:11:30,250
And if you can't see this size option, then just double check that your projection is in orthographic

159
00:11:30,250 --> 00:11:31,720
rather than perspective.

160
00:11:31,750 --> 00:11:33,220
And that may be a holdover.

161
00:11:33,220 --> 00:11:38,800
If you've created a 3D scene, then it usually comes in with a perspective camera instead of an orthographic

162
00:11:38,800 --> 00:11:39,250
one.

163
00:11:39,460 --> 00:11:45,250
So once we've selected that option from the dropdown, I'm going to make the size of this camera projection

164
00:11:45,250 --> 00:11:46,390
around about nine.

165
00:11:46,390 --> 00:11:47,920
I think that's a reasonable size.

166
00:11:47,920 --> 00:11:49,840
The enemies aren't too big on the screen.

167
00:11:50,260 --> 00:11:55,600
And then I'm going to go ahead and zoom out a little bit and move my enemy and my player around.

168
00:11:55,630 --> 00:12:01,600
So my player is going to start towards the bottom of the screen, maybe around negative six and by enemy

169
00:12:01,600 --> 00:12:07,000
is really just f a scale and they're going to come in, follow a path and then leave the scene.

170
00:12:07,740 --> 00:12:09,710
So you play an enemy set up.

171
00:12:09,720 --> 00:12:14,040
The last thing we're going to do in this lecture is set up the background image.

172
00:12:14,400 --> 00:12:19,320
Now, if we go ahead and look in Kenny's assets, he does have some backgrounds in here.

173
00:12:19,320 --> 00:12:21,450
So we could always use one of these.

174
00:12:21,450 --> 00:12:26,970
But I've actually gone ahead and created my own and you'll find a version of this attached to the resources

175
00:12:26,970 --> 00:12:27,870
for this lecture.

176
00:12:28,410 --> 00:12:33,480
So if we import that image into our project and I've just dropped mine in the assets pack, we'll go

177
00:12:33,480 --> 00:12:36,600
ahead and create an empty object called background.

178
00:12:38,100 --> 00:12:43,860
Again, we're going to want to reset the transform and then just drag our Sprite underneath that folder.

179
00:12:44,310 --> 00:12:48,990
Now we're getting a little bit of weirdness here because we can see our enemy, but our player seems

180
00:12:48,990 --> 00:12:50,190
to have disappeared.

181
00:12:50,340 --> 00:12:55,590
And as we found when we were looking at UI, this is because of the layers and the sorting orders.

182
00:12:56,070 --> 00:13:02,210
So over in our background star field image, let's just change the order in layer to negative one.

183
00:13:02,220 --> 00:13:05,490
This will place it behind our enemy and our player.

184
00:13:05,490 --> 00:13:07,760
And so both of them will now appear on top.

185
00:13:07,770 --> 00:13:12,420
And later on when we start getting a bit more complicated with our backgrounds, we'll start looking

186
00:13:12,420 --> 00:13:14,520
at this sorting layer as well.

187
00:13:14,730 --> 00:13:16,050
But that's good enough for now.

188
00:13:16,050 --> 00:13:21,150
And our project is all set up and ready for us to start looking at the new play input system in the

189
00:13:21,150 --> 00:13:21,930
next lecture.

190
00:13:21,930 --> 00:13:23,400
So I'll see you there.

