Hello, guys.
In this section, we're going to work on animations.
We're going to make simple animation like it'll run, jump and fall.
And to make that first, we need an animator.
I think it's best to practice on animations by making them, and we're going to do that.
And later, I'm going to tell you some more info about animations like how it works, how the transition
work and so on.
First, just repeat after me so it will be easier to understand later.
Let's select the player and then click add component.
And here I already have it.
We need to type animator and select it.
Now we can see that animator has controller field and we need to fill that with animator controller.
So let's click right button, create animator controller and we name it as player player, a C as an
animator controller.
Now let's select the player and drag it here.
There is also an avatar, but we don't need that avatar needed when you work with the 3D models and
rig skeleton and so on, so we don't have to worry about it.
Let's go to Window Animation Animator.
And now we can see what is inside of this animator.
So basically this window now shows us what is inside of this animator.
Now it's time to make some animations.
And for that, we're going to go to window animation.
Animation.
I want to take this window and drag it over here.
That's cool.
Now we can click create and I think it's best to keep it arranged.
So let's make a new folder that we're going to call animation.
So animation, see us.
Let's open it and inside I'll name it as player Idol.
Cool.
Now let's go to graphics player.
Idol folder.
Take all of the sprites and drag them over here.
We can click play to see how animation looks at the moment.
And I think it's kind of fast.
So we can make it slower.
We can do that by changing sample rate over here.
And in case you don't see sample rate, we need to go to this three dots, click it and choose show
sample rate.
To make it appear.
Now, let's try to set 15 over here and see how it looks.
Okay, that looks much better.
Now, if we go to any meter, we can see we got player idle animation over here.
Orange color means animation was set as a default.
Now if we go to play mode, we can see our character is moving.
He is in idle animation and basically that's it for this video.
We are done.
We made the animator controller and now our character is breathing and he looks more alive.
Before we finish, though, I want to do some changes in the script.
Let's go over here.
And first of all, I want to say we need to make a component animator because we're going to use it
later.
We have components on the game object, but we don't have access to components from this script.
So let's type here.
Public animator.
Anyone.
All right, let's save it.
Go back and drag it here.
Now we have access to the animator controller, but I actually want to keep this script a bit cleaner
and show as less info as possible, because later on, we're going to have a lot of stuff in there,
and it's going to be so huge it might not even fit into the inspector.
So there is a way to hide this rigid body animator and assign them at the same time from the script.
All right, let's go back to script and now I'll just make this window smaller so we can see.
Inspector, I will change this public to private.
Same as here, and I'm going to save it.
Now we go back to Unity.
We can see it's disappeared.
But still we need to assign it.
So how we can do that?
We can go to start function over here and type RB equals to get component, which is basically means
what it means.
RB will be equals to the value and that value is equals to get component of rigid body to dx.
And you're going to do the same for the animator animate equals to get component of animator.
Now it is not visible, but we have access to the component.
And if I try to play my game right now, I still can access rigid body, let's say from a jump.
Now I want to do something else in here.
It is best practice to keep variables private if you can.
If you don't have a reason to make it public, then don't do it.
And before we had the reason, because I wanted to see it in the inspector, but I didn't want to confuse
you with a lot of extra info that you don't need at the beginning.
But now I think you're ready.
So let's go over here and type private instead of public.
And now if we say it, you know it's not going to be visible.
So basically now we cannot change ground check distance because it's not here.
But we can fix that.
We can go and type serialize field just in front of it.
And while we are here, let's do same for Layer Mask.
Private.
And let's do the same for jumpers and move speed.
Let's make it serialized field private float and here as well, serialized field, private jump force.
Now, if I go back to Unity, I can see variables still there.
I can control them, but they are private and they are accessible only from the script and from this
script only if I try to get them from another script.
It is not possible because they are private.
Something else to mention here When you create in a private variable, you don't have to type private.
Exactly.
It could be just, let's say serialize, field float and power.
I'll just type power.
This is an example.
Now, if I go back to Unity, it happens.
Because if you don't mention is it private or public, it's going to be private by default.
And let's say when you prototype in, it is really handy to just quickly type float power instead of
private and wasting your time for that.
But I prefer to type it so it's easier to understand, especially for beginners.
All right.
What is private and what is public?
That's enough for this video.
And let's go to next one.