Once we making our player game object jump at the same time, we need to play the jump animation clip.
We're not playing at all.
So let me show you.
Let's click on this play button in the top to play our game, and let's have a look on it.
So once we just making our player jump it's the jump animation.
It's not playing.
We just playing the run animation clip over again and again.
So if I press down space key on my keyboard, as you can see we just still playing the running animation
clip.
Even we are in the air, so we need to play the jump animation clip instead of the running.
So let's get out of play mode.
And if we select our player GameObject in the hierarchy, then move over to animator tab.
As you can see in previous chapter in animator, once we created those animation, or you can simply
say in Animation Transition chapter, we just said this jump parameter.
So this jump which is a bool parameter which can be true or false.
So what we basically need we need to set this jump parameter to true.
And we do know once we set this jump parameter to true, it's going to play the jump animation clip
right away.
So what we need if we select our player game object and then move over to Inspector, we can see an
animator component is attached to this player once we created those animation clip.
Basically this running as well as the jumping animation clip.
So once we created those animation clip, this animator component just added right away.
So what we need, we need a reference of this animator component.
And then we can set this jump parameter to true or False depending upon what player is really doing.
We need to do that.
So we do know we need a reference.
Then we can set this parameter.
So let's grab the reference first.
So we're going to open up our player script.
So let's select the player GameObject in the hierarchy.
And let's open up the player script by double clicking on it in the inspector.
So we need a reference.
So let's go to the top of our class so you can make it anywhere you like.
So I'm gonna make it underneath this rigid body feel.
And we're going to make it public because we're going to set this underneath our player script, right
underneath our player, somewhere over here in the Inspector.
And the component we're looking for is a animator.
So we need to type this animator, the component we're looking for.
And we also have to name the reference what we want to name it.
So I'm going to call it something like animator with Non-capitalized a letter.
And let's close that up with semicolon.
And let's press down control S in order to save our script.
And let's move over to unity.
So we need a ref.
We basically need to grab the reference first.
So underneath our player script we're going to able to see another field just going to appear.
And it will be animator.
So as soon as the player script gets compiled we can see underneath our player script an animator component
just appear.
So by default it's just going to be none.
Something like this basically means empty.
So what we need to do, we need to select this animator component of this player game object and drag
it into this field.
So we're going to have the reference.
And then we can set this jump parameter.
So let's take this animator component and let's drag it over to this animator slot or animator field
file.
And now we can see we have player animator reference.
Now we are ready to set this jump parameter.
So let's open up our player script by double clicking on it.
And let's go where we're jumping.
So we're doing over here as you can see if input dot get key key Codespace basically means if we press
down space key at the same time we are standing on the ground, then what we're doing, we're just making
our player jump and then we're setting a ground parameter to false.
So we also need to set that jump parameter to true.
And we do know once we're gonna set this jump parameter to true it's going to play the jump animation
clip of that player game object right away.
So we're going to do it inside this curly brackets because we're doing we're just making our player
jump over here.
So that's why after making the jump We also need to play the animation clip.
So we're going to use this animator.
So we do know we have the animator reference as you can see.
So I'm going to use this animator in order to set the parameter.
So let's use this animator.
And we're going to use this dot set function and make first packet.
So why we used this set bool function.
Because if we move over to unity we can see in animator component we just created this jump parameter
which is bool parameter which can be true or false.
So that's why we need to use this set bool function in order to set the parameter.
So as a first argument this.
Set bool parameter set bool function.
It's going to take the parameter name in quotation, so make sure your users is spelling it correct.
So make sure you just move to unity and see the see the name of the parameter in this animator tab.
So we can see the parameter name is jump.
So as a first argument we need to pass in quotation the parameter name.
So I'm going to make make sure you just do in quotation inside this quotation.
And the parameter name is dumb.
And the second thing, comma, it's going to take the value that you want to set.
And we do know once we take this parameter to true basically means if we set this parameter to true,
it's going to play the jump animation clip right away.
So we need to set this parameter to true.
So let's set the value.
So second thing it's going to take the parameter.
Uh it's going to take the value.
So we're going to set it to true means we're just taking that parameter and then close that up with
semicolon.
So if you haven't watched that chapter or that section in which uh, chapter or section, we just created
the animation clip, you can go and check that out.
If you just a little bit confused then you can check.
So make sure you just press down Ctrl S in order to save your code.
And let's move over to unity.
So once we press down space Key we're going to able to save which is setting this parameter to true
means checked.
So the jump animation is just going to play right away right after we just make our player jump.
So let's click on this play button in the top and let's have a look on this.
So just wait for a little moment.
So if we press down space key on our keyboard as you can see we just made the jump.
But the problem is that we're not playing our run animation clip again.
We just stuck in jump animation clip forever.
So as soon as this player game object is gonna collide with this ground, then at that moment we need
to play the run animation clip instead of jump.
So what we need if we click on this pause button in the top, in order to pause the game, we need to
set this parameter to false basically means uncheck.
And once we just manually do it, if we just manually do.
And then click on this pause button in the top to play the game one more time, we can see it's now
playing the running animation clip.
So let's get out of play mode.
So we also need to set back this jump parameter to false.
Basically uncheck.
But when we shoot once this player game object collide with this ground, at that moment, we're going
to set this jump parameter to false.
And as we're going to set this jump parameter to false, it's going to play the run animation clip because
we have chosen the condition.
If we select the back transition from this jump to run an inspector, we can just take a look.
If we scroll down we can see if jump parameter is false, then it's going to play the run animation
clip.
So we also need to set back this jump parameter to false.
So let's do that.
So let's open up our player script one more time.
And we're going to move over to this uh collision function.
We do know we're just taking over here.
If we're colliding with uh with this ground or not.
So we're doing over here, as you can see.
So once we collide with this ground, we just are setting this ground parameter to true, as you can
see.
So once we collide with this ground then we're just setting this ground parameter to true.
So true to jump for the next time as well.
Sorry.
Uh, I guess true.
Yes.
So what we're doing we're just setting is ground parameter to true.
So we also need to set back that jump parameter to false.
So what we need, we need to move over to this animator component.
And we're going to use the set bool function one more time.
And first thing we do know it's going to take the parameter name in quotation.
So in our case jump.
So make sure you just spelling it correct to check it.
You can just move over to unity and then animator type tab.
And the second thing it's going to take the value.
So we're going to set it to false.
And let's close that off with semicolon.
And setting it to false basically means unchecking.
And we do know once we're gonna uncheck it's gonna play the run animation clip right away.
And where we just unchecking once whenever this player came up to collide with this crown as you can
see over here.
So firstly we just moving over to animator and then setting.
So basically we're just moving over to this animator of this uh basically player a game object.
And then we're just setting this parameter by this animator component reference.
So let's uh, press down Ctrl s to save our script and let's move to unity.
So as soon as this player came up to collide with this ground, you will see the run animation.
Just gonna play right after this player came up to collide with this ground.
So let's have a look on this as well.
So let's click on this play button in the top to play our game.
And we're going to take a look on that.
So just wait.
And now if we press down space key on our keyboard as you can see it's just playing the jump animation
clip.
As soon as this player GameObject just collide with this ground, we can see this player game object
is now playing the run animation clip.
But once we pressed on space key on our keyboard and just playing the jump animation clip, and as soon
as this player came up to collide with this ground, then it's just playing the run animation clip.
So I'm gonna get out of play mode.
I hope you get the idea that how you can do it.
And one thing we just forgot to do that is to restriction about that rotation.
So let me show you first.
If we select our player GameObject in the hierarchy, then move over to Inspector, then transform and
then play around with Z rotation to this rotation section and play around with z rotation.
We can see our player GameObject is weirdly routining.
So to stop that what we need to do.
Firstly, I'm going to set back z rotation to zero to restore or to register that or to restrict that.
You need to move over to this rigidbody 2D component of this player GameObject, and then scroll down
a bit and then move over to this constraint.
Click there and freeze the rotation about z axis.
Basically check that and now the rotation will be restricted in this z axis.
So it's not gonna rotate like that.
And that is the thing.
And also make sure you just go to inspector then overwrite and then click on this apply all.
So the changes you made it's going to be saved into this player prefab game object as well.
And we're going to press down Ctrl S to save our project.