Now what we need to do, we need to call the function.
So basically once we're going to click on this jump button we want to jump.
So we need to call the jump function.
So if I move over to my hierarchy then canvas then UI and then select this jump button.
Then go over to Inspector.
Scroll down.
We need to call the function right over here.
So once we're going to click on this jump button.
So we need to call the function here.
And we do know that we have done inside our player skip.
Uh basically we need to select our player game object in the hierarchy.
So I'm going to select my player game object in the hierarchy I have it over here.
So let's select that and let's open up the player.
Skip in Inspector by double clicking on it.
And if we scroll down we have the jump function.
Something over here.
We need to find it.
So as you can notice we have it over here.
And make sure you just mark your function as public so we can call through a button.
So what we need to do we need to call the function uh we need to call this jump function.
And what jump function is really doing.
It's basically jumping our player, as you can notice in the y axis and basically in the y axis and
in the zero.
Uh sorry.
In the x axis zero.
So let's call the function.
So let's move over to unity and let's select our jump button.
So for that I'm going to move over to canvas UI and select this jump button.
Let's go over to Inspector.
Scroll down to the bottom says Button component.
And let's click on this plus icon.
So we need to drag the GameObject in which GameObject the script is sitting on.
And we do know we have done inside our player script.
So we're gonna drag our player GameObject right over here because the player script is sitting on our
player GameObject.
So I'm gonna move over to my other stuff.
So I'm going to select my player.
Let's drag it there and it says no function.
So let's click on it.
Let's go to Player script right over here in the bottom we can notice.
And inside our player script, we can see we created the jump function.
So we're going to choose that.
So now we have chosen.
So if we click on this play button and then try to click on this jump button, you will see our player
game object.
Just gonna jump right away.
So uh, we're gonna basically as, as soon as we're gonna click on this jump button, we can just make
the jump.
So if I just click on this jump button, as you can notice, we're jumping.
But the problem is that we can jump as many times we want, which we really don't want, and we do know
we're doing inside that.
Uh, basically our, uh, once we click on this space button on our keyboard, we basically making the
jump.
And there we checking.
So instead of doing that we're going to do something else.
So basically what we need to do we need to get out of play mode and then move over to player script.
So over here as you can see we just making our jump.
So before we jump we also want to check if we are grounded or not.
If this player is touching the ground, then we want to jump.
Else we're not gonna jump at all.
And we do know that if we move over to our skip and then move over to our update function, uh, right
over here.
As you can notice, if we press down space key at the same time, total jump is zero.
F basically means we have, uh, more than one jump.
So instead of checking over here, we're going to check it there.
So what we're going to do we're going to remove this.
So let's remove this and also remove this total jumps right over here.
And we're gonna do it inside our jump function.
So before we jump what we want to check, we just want to check if our jump is greater than zero.
If so we're going to check.
So before we make our jump.
So let's make first bracket and some curly brackets.
So what we want to check over here.
We basically want to check if our total jumps if it's greater than zero f.
And we do know that in the start of the game we just doing it.
So what we're going to do now, we're going to put this line of code by Ctrl X for cut.
We're going to paste inside Ctrl B basically what we're doing, we instead of doing inside our uh input
dot get space right over here.
We basically doing here inside our jump function as you can notice.
And after jumping what we need to do we need to subtract our total jumps.
So we will subtract total jumps minus minus basically.
So subtracting one.
So before we jumping uh what we're doing we basically checking if our total jumps is greater than zero
f.
And in the start of the game we just set total jumps to two, something like that.
And we do know that two is greater than zero f or one something like that.
So the condition getting true.
So that's why we're going to jump.
And after jumping we just subtracting total jumps.
And we do know that this total jumps somehow it's going to hit zero.
And when it hits zero, if we move over to our update function when it is zero, it's ground is true.
Basically means player basically standing on this ground.
Then what we're doing, then we're setting total jumps again to our extra jumps.
And by default we have set two.
So this right over here total jumps.
Getting one more time two and two is greater than zero.
So the condition getting true.
So that's why we will able to jump for the next time as well.
And now what we need to do we need to press down Ctrl s to save our script.
And now let's move over to unity.
Basically we're doing the same things.
And instead of doing if that if condition basically inside our update function, we basically turn inside
our jump function.
So basically that is the cool thing.
Now even if we press down space key and also this jump button, it's going to do the same thing because
we're doing inside jump function.
So that's why.
So let's have a look.
So just wait a moment.
So once our compilation is done, we can just check that out.
So I'm going to click on this play button in the top in order to play our game.
And let's have a look on this.
So as soon as we're gonna click on this jump button we will be able to jump.
And once we jump two times then we're not gonna jump at all until and unless we hit our ground one time.
So if I just click on this jump button, as you can notice, we not able to jump anymore.
Uh, basically we jumping three times, but more than three times we not able to do it and we able to
do it once this player game object touching this ground then we just resetting total jumps to our extra
jump.
And if I do the same thing with my space key, we can see it's doing the same thing because we have
done all of the things inside that jump function.
So that's why.
And we're gonna talk about this attack button.
Now if I just left click on my mouse button.
We can see we're just playing our attack animation for now.
I'm gonna remove that.
If I just click left mouse button, I don't want to play the attack animation, but if I click on this
attack button then I want to do it.
So for that, let's get out of play mode and I'm gonna move over to my script and let's move over to
our update function, where we basically playing our attack animation right over here, as you can notice.
So I'm going to make this one comment by double forward slash.
And we do know that the comments basically don't interrupt our code.
And if I press down Ctrl s then move over to unity and then click on this play button.
You will notice if we click the left mouse button, we're not going to able to play the attack animation
clip anymore.
Uh, so for testing purpose purpose I'm just doing that and we're gonna hook that with this attack button.
So once we're gonna click on this attack button, I want to play the attack animation of this player
game object.
So if I just go add and then click on this play button and then try to click left mouse button, you
will notice our player not gonna play attack animation at all.
So for testing purposes I'm just doing that.
But once we're gonna click on this attack button then we just want to do that.
As you can notice, I'm just clicking the left mouse button.
It's not playing the jump basically attack animation.
But once we click on this, uh, you can simply say this attack button will not able to play our attack
animation.
So basically what we need to do, we need to hook this attack button with our attack animation.
So let's get out of play mode.
And for that we're gonna move over to our skip and let's move over to our play attack animation function
where we made it.
So right over here, as you can notice, we just, uh, we just, uh, made this function.
And this function is responsible for playing our animation clip, as you can notice, which is attack
one, attack two, and attack three.
So we need to call this function through our attack button so we can see we just this function is marked
as private.
So what we want to do, we're going to make this function public.
So we can call the function uh through our button.
So let's mark this function as public.
And now we're going to press down Ctrl s to save our script.
And now let's move over to unity.
And we're going to hook that play attack animation function basically that function with our attack
button.
So just let's have a look on that.
So we're going to so we need to hook that function with our attack button.
So just wait a little moment.
And once we are done we can just hook that function with our attack button.
So for that we're going to head over to hierarchy.
Let's go to canvas UI and let's choose this attack button.
Let's go over to Inspector.
Scroll down to the button component.
And we can notice on click and it's empty.
So let's click on this plus icon.
And we do know that we need to track the game object and which game object the script is sitting on.
So in our case player.
So let's select that.
Let's drag it there and it says no function.
So let's click there and we will move over to player script in the bottom.
As you can see our player C class.
And in there we created play attack animation function as you can notice right over here.
So we're gonna choose that.
And now as soon as we click on this button it's going to play our attack animation clip of this player
game object.
So let's check that out.
So I'm going to click on this play button in the top in order to play our game.
And let's take a look on this.
So you're gonna see that as soon as we click on this attack button it's going to play our attack animation.
So if I just click on this attack button, as you can see by now, we can notice that we're playing
our attack animation.
But if I click left mouse button we're not playing our, uh, attack animation at all since basins.
We just, uh, we just comment that function once we click the left mouse button, which is, uh, that's
why it's not interrupting.
Basically not displaying our attack animation once we click our left mouse button.
But once we click on this attack button, we can notice it's playing the attack animation.
Basically, it's working fine.
And we can just click on this right or left arrow to move left and right.
And we can just click on this jump button to jump as you can notice.
So basically it's working fine.
And I hope you get the idea.
And I'm gonna get out of play mode and make sure you just move over to your UI game object.
Basically the parent one, if you turn it into a prefab then go over to Inspector Overrides and then
apply all.
So the changes you made inside this attack and this jump button is going to be saved into this UI GameObject
prefab as well.
So I hope you get the idea that how you can hook a function with a button with a button to do a specific
things.