[MUSIC]
>> Thank you guys for joining today,
we are going to do an overview of Unity.
We're going to walk you through it.
You're going to know all about it by
the time we're done. What is Unity?
How to get it, how it works,
understanding the interface, bringing in assets,
installing a text editor,
writing simple scripts, where to go and how to continue learning?
Unity is a game engine,
but it's also used for a lot of other stuff.
It's being used for things like
architectural visualization or animation
and cinematics, special effects.
It's a great way to create interactive programs to train people.
I work in Unity every day,
I love it, I use it for game development.
Now that you know what Unity is,
you might be wondering, well, how do I get Unity?
The answer is, you go to unity.com. Here's the website.
You can click on the "Get Started" button
and here are the commercial products.
I have plus a pro over here,
I'm an early plus user.
If you're just starting off,
you can use the personal edition until have
a revenue or funding of over 100,000 in a year,
then you need to upgrade.
To get it, you just click on
"Get Started" and you're going to want to get
the Unity Hub to download. This is what it looks like.
It's this little window here that pops up
and it's like you're about to open a program.
But if you don't have Unity installed yet,
you're going to need to do that first.
When you get this for the first time,
there should be an Add button where you
can add a version of Unity.
You can go to your installs as well and install the editor.
Once you start making projects, this is where they show up.
This is the name of them, the file location,
when you last modified them,
but also importantly, the version number of that project.
You might have games using different version numbers,
which is why the hub is so important.
Let's look at how Unity works.
We're going to start off by making a new project together.
This will take a second to put together.
We're going to click "New Projects", Karting Microgame,
2D Mobile, First-person
Microgame so there's a lot of stuff here you can choose from.
We're going to click "Blank 3D Project", which is 3D core.
Unity demo project and I'm
going to put in a folder that makes sense for me,
and now it's going to create that project.
The next thing we're going to cover before we start using this
and looking closely at it is how Unity works.
You will be using C-Sharp in Unity.
Even though it's built-in C++,
that's all the behind-the-scenes stuff.
You don't need to worry about it.
We're focusing on C-Sharp when we're using Unity.
You're going to need something to write your code in.
You can use an IDE,
Integrated Development Environment or you can use
a Text Editor that both of them you write code in.
I use VSCode we're going to look at that shortly.
All the items in your game are called GameObjects.
GameObjects have a position,
they have a size and you can add on something called components,
like modular pieces that you can attach to
a GameObject and that will give it its properties.
Whether it has a renderer which allows you to see it
or a collider which allows you to bump into it.
These types of properties are all within a component and you can
change those values of
that GameObject within that Component's details.
Let's look at the interface.
Isn't it beautiful? Now,
here it says the name of my scenes; Sample scene.
We have our GameObjects that are in
the scene here and if we click on one of them,
on their right over here is our Inspector tab.
This shows all the properties
of our GameObjects here in
our hierarchy. This is what's in our game.
In the current scene,
you can put your whole game into one scene.
If it's a more complex game,
you might want to have different scenes.
This scene will be our whole game.
The hierarchy shows all the GameObjects in
that particular scene and
our project folder down here, here, you can see.
Let's see assets that's in our project folder.
These aren't necessarily being
used in the game when they're in our folder,
but they're available for us to use if we want to.
We can drag items from our scene into our hierarchy,
and that's how you bring them into the scene.
We can right-click over here in the "Hierarchy",
we can select "3D Object",
and then we can select "Cube",
and use our mouse wheel to scroll in and out.
Now you see this cube in the world.
This is in our Scene View here.
Scene View is the middle thing that
has all the developer information.
It's not going to look as good as your full game,
but you can turn on the lighting and turn off the lighting,
you can change the angles,
you can look at in all different ways.
This is our Scene View, it's where we do our work.
When we play the game, we're playing in Game View and this is
a preview of our current camera's view,
and what you'll see if you play the game.
Our directional light here.
You can see the color blue.
We can change things in
its properties going into some of these values,
you can change the intensity.
You can see it's being reflected on this cube here,
higher, lower, and on the cube.
You can also change things like the scale,
so we can set it to be 100 by 100,
now you have a ground.
This is the position right in the middle of the scene, 0.0.0.0.
On the cube, we have the Mesh Renderer,
which shows the cube and the Box
Collider so that things will collide with it
and we can actually have physics
basically taking place with that object.
Next, we're going to start looking at
controlling items within the same view a little bit more.
Let's add another cube by right-clicking on our "Hierarchy",
selecting "3D Object", and selecting "Cube".
Now we have a cube on our cube.
You can see that this has what's called a Manipulator,
which is these three arrows in different directions.
When it's set to the three arrows,
that means you can use those to move it
and that will affect the position over here when
you select it they will turn on and
if they're not showing up when you click it, you press "W".
If you press "E",
you now have your rotation options here.
Finally, "R" will bring up the ability to scale your objects.
You can do this with a number of values over here,
or you can do them with the manipulators to do it more visually.
You can also see me here moving around the scene like this.
This is something I use a lot.
You can do that by holding "Alt Down"
and then using your left mouse button in
order to get the different views and check things out.
Middle mouse button scrolls in and out,
and middle mouse button down
and drag is how you pan around the scene.
You can also do a pivot view with your right mouse button.
I don't really use this one that much,
but it might be useful to you.
If you get far away from your object and you're like, oh no,
click the object you want to focus on and press letter "F",
and it will zoom right in and center in the middle of your screen.
We're going to next look at
the bringing objects in from the Assets Store.
There's a tab here open called Asset Store.
If you don't see it, you can click "Window" "Asset
Store" and you can scroll around and see what's here.
You can search for something you want.
You can click on pricing and select free assets.
We're going to click "Free assets".
Let's click on the "Low Poly Tree Pack",
"Add to my Assets", "Accept".
Now it's adding and I can "Open in Unity", "Open Unity Editor".
There it is, Low Poly Tree Pack.
There it is at the bottom list.
Now that we can see it in our Package Manager,
we can click "Download" and I'll bring it into our project.
"Import". Import again,
this shows you the files that are listed and
now we can close our Package Manager and over here
we can see that we have some files added in our Assets Folder in
our Project Folder here and within it we see different items.
If we click on "Prefabs" and they're all set to go,
so we're going to drag one in.
You can either drag it from our Project Folder into
our scene or into our hierarchy. Let me show you both.
We drag one here into our scene.
We can position it or we can drag it into
our hierarchy and that brings it into
the middle of the scene, the origin.
We can then move it around so you can go
ahead and decorate some scenes right off the bat.
It's really fun to play around in.
We're going to look at some basic scripting.
One thing you're going to want to do next is install
a Text Editor or IDE so that you can code.
We're going to use VSCode which I really love working with.
You can link Unity to it using going to "Edit References",
"External tools", and then you can select it from the list.
You may have other ones installed.
You can choose which you'd like.
I'm using Visuals Studio Code.
Here it is on the list and that will
link together so that when you make a script,
you can click on it and it'll automatically open that program.
We're going to right-click in our
"Project Folder" and create our first script.
Right-click on the "Project Folder",
select "Create" "C-Sharp Script".
Here we have a file with a big hashtag on it,
and we're going to write color change.
Now, we have a name for it.
We double-click it. Once you have your Text Editor
or IDE integrated with Unity linked together,
it will automatically open up when you double-click this script.
This is what a default script looks like in Unity.
You'll notice it says color change here.
You want to make sure that this word here,
this whatever this says,
matches identically to the name of the file because otherwise,
you're going to come into some problems.
These are some of the libraries that we're
using with Unity by default,
you're probably going to keep them there, for the most part.
We're going to do
a simple script where we change the color of this cube.
As you can see right now,
with the lighting being pink, it's hard to tell.
We're going to just set the lighting to be white.
We're going to change the color of it.
To do that we're going to apply two different materials.
We're going to right-click in our "Project Folder",
"Create" "Material", we are going to call one red,
and here is our red material.
We double-click it, or if we click on it,
here is a properties of it.
That the Albedo here,
click on that and we're going to set it to "Red".
Now that you see this updated as red in here we can
drag it onto our cube here or over here,
and now that GameObject has that material as a component.
Now, we're going to create another one.
We can click on that press "Control D"
we've duplicated it now we have Red and red one,
rename this to blue.
We can then click on it,
make sure it's selected and change our color to a blue color.
We want to do that with script. We want to do it in code.
The first thing we want to do is be able to grab the cube.
We know that what we're changing in the script.
Let's say "Serialize Fields".
Here's a cube and we can drag
this script onto the cube
just like we did with the material and you can see that here,
"Color Change Script" and there's no properties yet,
it's just a blank script so now if we select "Serialize
Field" and type "GameObject" capital G capital O,
and we're going to say "U", and then semicolon.
That's all the script we need for this to now
have property that we can fill in.
We select it again, you can see here Cube None GameOb,
so it's looking for GameObjects.
There's nothing here, what we can do is take this cube over
on our hierarchy and drag that over here,
and now our script is going to be connected with this cube.
From here, we can now
change properties of this cube with this script.
We're going to serialize
two more fields and they're both going to be materials
because we want to be able to change
them so let's Serialize Fields.
We say "Material" we say "Red" and then, "Blue".
Now there's two separate ones.
The comma will separate
different materials that you want to
add to this. These are now added.
We have all three items connected to our scripts.
Now let's tell it to do something.
What we're going to do is when our bot mouse clicks in the scene,
we want the color to change.
In order to check when the mouse is being clicked,
we need to be checking on each frame for it.
We're going to say "Void" because it's not returning everything.
If you don't return something it's
just going to have Void in front of it.
We're going to say "Void Update" and that
is the function you run that will happen on each frame.
You can say "Cube GetComponent".
We can get the component that we had listed over here and we
want to get the renderer because that's what
you change when you change material.
It's written like this GetComponent in
brackets with more brackets afterwards so we're going
to put "Cube Transform" and then we're going to
say material equals blue.
We need to call this if we do this,
it will happen right away and it'll happen every frame.
If Input get mouse button
down then we can put that within the brackets.
Now should only happen once we click.
We can click our Scene and it should change to blue.
There we go. Very good.
Only one more little thing.
Just to give you a little bit more insight in the code.
We're going to create something called a Bool or
Boolean and because we haven't serialized it,
it won't show up on our properties, but we don't need it to.
Then we're going to call so this is a type and we're
going to say Is Red and we're going to
set it equal to true when we
start because we're starting it as red and
now we can send another if statement
here so when we press the mouse button down,
we can say If isRed and then within that we set it to blue else,
so like otherwise, we can set the cube to red.
Very similar, we can copy and paste this code.
Every time you click it and we'll go back and
forth as long as we change this Bool.
If it's red, we now need to say If isRed is true,
we're going to set isRed to false and
then if it's false and we go to the else case,
we're going to want to set it to true again and
now we have it set up as you go back and forth.
Look at that. What a great game.
Hopefully that all made sense.
I know it's a lot to take in.
There's so much that goes into game development.
You could publish your first game within a few hours of learning.
It would probably be something very simple,
maybe a little bit more than this.
You can get started and it can be a
really fun and fulfilling hobby.
I always recommend people to get into Unity, try it out.
Everything's free and there's so many resources
available to see if you like it, because, why not?
It doesn't take long and it can potentially be a lot of fun.
[MUSIC]