In this lecture, we're going to set up our Laser Defender project and also do a little bit of messing
around with the unity editor.
Because as you can see here, I'm currently in a Unity 3D scene, and that is because when I created
this project, I accidentally on purpose clicked on the 3D preset instead of 2D.
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
automatically set 2D when you create your project.
Now, to save you some time, you are probably going to be better off just starting up a new project
and remembering to set that 2D option.
But if you are in a 3D project, then let me walk you through some of the set up we're going to have
to do and some of the pitfalls and challenges we're going to face later on in development.
So the first step to setting up our project to act like a 2D project is to go over into the hierarchy.
And rather than just having a main camera, we've now also got a directional light.
We're not going to need this for a 2D game, so we can just really go ahead and delete it.
This will leave us with just our main camera.
And in here this is set up for 3D as well.
So over on our camera component, the first thing we probably want to do is change our projection mode
from perspective to orthographic.
Finally, we want to remove our skybox and just have a flat background so we can change our clear flags
from skybox to solid color.
But in our same view, we can still see the skybox.
So let's have a look at how we get rid of all of this and just work with a plain flat background up
at the top of our same view.
We have a whole bunch of options and to get rid of the skybox, we want this little stacked icon with
the plus sign above it and we can either disable all of that entirely or in the dropdown we have a whole
bunch of options where we can select whether we can see our post-processing, our particle effects and
things like that.
We will be using particle systems, so let's leave that on.
But instead switch off our skybox, our fog.
And since we're not going to need it, we might as well turn off our flares as well.
Finally, up in this top bar, we also have this two D button.
And if we click on this, it will change our camera and put us into a 2D flat view.
Now, back in previous versions of Unity, this is pretty much all you'd really have to do.
However, in the more recent versions of Unity, all of the 2D assets and packages have all been wrapped
up separately to the 3D environment.
So if we were to say go ahead and right click on our hierarchy, we'll see that we've got 3D objects,
but we don't have any 2D objects, so we can't add any sprites to the game.
Now to fix this, it's just a case of coming up to our window and then down to our package manager.
And if we go ahead and select the unity registry right at the very top, we'll have a load of two D
packages that we can choose from.
Now, if you've set your project up as 2D already, you'll notice that pretty much all of these are
already installed.
The only one missing will be the 2D tile map extras.
At its most basic, the only one you really, really need is the 2D sprites.
So let's go ahead and install that first.
And once that's installed, if we go ahead and right click on the hierarchy now, we'll see that we
have our 2D objects so we can now add the sprites to our scene.
And we're not really going to be using any of these other 2D options.
But if you want to go ahead and sell these anyway and then your project will be in exactly the same
state as it would have been had you selected the 2D option when creating the project.
Now, while we're in the package manager, we may as well go ahead and set up the other packages we're
going to need for our project as well to get that out of the way.
So let's go down and double check that we've got our Tex mesh pro installed.
And the last package we're going to need if we scroll up is going to be the input system, because for
this project we're not going to be using the old inbuilt input system with unity.
We're going to be using their new fancy input system.
So let's go ahead and install that as well.
Now during this install process, you will be presented with this warning message and this will ask
you if you want to restart the editor and disable the old unity engine inputs.
So let's go ahead and click.
Yes.
And this will finish off the installation process and then restart unity.
And this might take some time to just re-import everything and reload the editor.
So once the editor has reloaded, let's go ahead and close the package manager.
And don't worry too much about that input system that we've just brought into our project.
We'll get there and we'll look at it in a lot more detail when we start moving our player around the
level.
Now, the next thing I want to show you in here is how to change your editor around and save new layouts.
Because when I'm working on a project, I'm not actually a massive fan of having my hierarchy over on
this side of the screen, because a lot of the time I need to access something in the hierarchy and
then do something in the inspector, and we can move and rearrange all these elements on our screen.
If we click on the tab at the top that says hierarchy and then just click and drag.
So left click and move it around, we'll see that we can move it around to different areas of the screen.
So I'm going to drag it to the right of my scene view and snap it into place.
And for this particular game, I'm also going to take the game window and just snap it to the left of
my scene view so I can see my game and my scene in the same view.
Now you can continue to drag and drop different areas of your screen and set up your editor however
you like.
Once you're done, if you go up to the top right dropdown where it says layout.
We can go down and save our new layout here.
We can give it a new name and we can really name it whatever we like.
I'm just going to call mine the laser defender layout or lrd layout and hit save.
And now if we click on our layout dropdown again, we'll see that we've got our LD layout in our list.
So if we want to go back to default, we can click on our default option.
And if we want to go to our laser defender layout that we've created, we can click on that.
Okay.
So with our layout now set up, I'm actually just going to open this up a little bit more so we can
see some of the other options that we've got here.
So we can always resize and move however we like.
But for now, the only one I really want to see is this free aspect dropdown, and that's because we're
going to change our aspect ratio for our game.
Our space shooter is going to be somewhat mobile friendly, so I'm going to go with a nine by 16 aspect
ratio.
I've already got a pre created one in my list here, but if you don't have that, then you can just
click on the plus button, give it a name.
So nine by 16, change the type to aspect ratio and then just specify the width and height that you
want.
So in this case, it'll be nine on the X and 16 on the Y.
Then if we go ahead and click on our nine by 16, we can kind of see why this layout is nice for our
game, because we can hide our game window all the way to the side here and still see everything that's
going to be going on on screen, but then have a nice large workspace for working in the scene itself.
Next for our product set up, we're going to need some assets and that is going to be your challenge.
So I want you to find some suitable assets for your game and then I want you to create a prefab for
your player, a prefab for your first enemy.
And I also want you to add a background to your scene.
So you pause the video now and get that set up.
Okay.
Welcome back.
So hopefully you found some assets for your project and for mine.
I'm going to be using some that are available from Kenny.
And if you've never heard of Kenny before, then he's a very generous and prolific game developer who
offers a lot of assets on his website completely for free.
So if we go up to the assets, you'll see that there's a whole bunch here available all under the CC
zero license, meaning you can use them for both personal and commercial projects.
And the first one I'm going to be looking for on Kenny's website is called Space Shooter Redux.
So let's search for space shooter and it's this top one here and then we can go ahead and download.
Now, even though these packs are completely free of charge, if you do have the resources, then do
consider donating to Kenny so that he can continue to do this great work of providing free and open
source assets for us aspiring game developers.
And once that's finished downloading, we'll bring that into our project in Unity and back over in Unity,
I've put mine in its own folder called Asset Packs and we've got our space shooter assets.
So in here if we go into the PNG folder, we're going to need a player ship and we're also going to
look for our first enemy.
This is where we're going to run into another problem, if we started off in a3d scene, because if
we select one of our sprites, we'll see that the texture type has come in as default.
And if you're in a 2D project, which hopefully you are, you'll see that this by default is set to
Sprite.
This means for every image that we ever import into our 3D project that we want to use for 2D, we're
going to have to change the texture type in the dropdown to Sprite 2D in UI.
Then once we've set this, we'll notice a few changes have been made and then right at the bottom we're
going to have to apply.
Now, luckily, we can do a lot of them in one hit so we can highlight the whole bunch and then change
all of them to sprites and apply.
Once we've gone and done that, we can then use all of these images as regular sprites like we would
do in a regular 2D project.
Now back to setting up our player.
Let's right click in the hierarchy and create a new empty object called player.
Let's reset the transform for now and then choose one of the available player ships.
I'm going to go with this blue one with the nice swept wing and I'm going to drag and drop that underneath
the player with our base player set up.
Let's go ahead and prefab them.
So back up in the top level of the assets folder, let's right click and create a folder for our prefabs
and we'll go ahead and drag and drop that into that folder.
Next, we're going to want an enemy.
So let's right click in our hierarchy, create a new empty game object and reset the transform.
Let's call this Object Enemy Zero because we may create more enemies later on, and as programmers we
start counting at zero under our enemy.
Let's find a sprite to attach to them.
I'm going to go with this little red one here.
And once again, let's go ahead and drag that into our prefabs folder.
Now, if we have a look over on our game screen, we've got both of them occupying the same space at
the moment.
So we'll move them around in just a moment.
But first of all, we want to consider the size of these objects on our game screen.
And I think these are just a little bit too big at the moment.
So if we click on our main camera and then in our camera object, let's look at the size.
And if we increase the size, we'll notice that we zoom out from our game.
And if we decrease the size of our camera, we're going to zoom in.
And if you can't see this size option, then just double check that your projection is in orthographic
rather than perspective.
And that may be a holdover.
If you've created a 3D scene, then it usually comes in with a perspective camera instead of an orthographic
one.
So once we've selected that option from the dropdown, I'm going to make the size of this camera projection
around about nine.
I think that's a reasonable size.
The enemies aren't too big on the screen.
And then I'm going to go ahead and zoom out a little bit and move my enemy and my player around.
So my player is going to start towards the bottom of the screen, maybe around negative six and by enemy
is really just f a scale and they're going to come in, follow a path and then leave the scene.
So you play an enemy set up.
The last thing we're going to do in this lecture is set up the background image.
Now, if we go ahead and look in Kenny's assets, he does have some backgrounds in here.
So we could always use one of these.
But I've actually gone ahead and created my own and you'll find a version of this attached to the resources
for this lecture.
So if we import that image into our project and I've just dropped mine in the assets pack, we'll go
ahead and create an empty object called background.
Again, we're going to want to reset the transform and then just drag our Sprite underneath that folder.
Now we're getting a little bit of weirdness here because we can see our enemy, but our player seems
to have disappeared.
And as we found when we were looking at UI, this is because of the layers and the sorting orders.
So over in our background star field image, let's just change the order in layer to negative one.
This will place it behind our enemy and our player.
And so both of them will now appear on top.
And later on when we start getting a bit more complicated with our backgrounds, we'll start looking
at this sorting layer as well.
But that's good enough for now.
And our project is all set up and ready for us to start looking at the new play input system in the
next lecture.
So I'll see you there.