WEBVTT

00:00.040 --> 00:02.880
Now what we need to do, we need to call the function.

00:02.880 --> 00:07.440
So basically once we're going to click on this jump button we want to jump.

00:07.440 --> 00:10.160
So we need to call the jump function.

00:10.160 --> 00:16.000
So if I move over to my hierarchy then canvas then UI and then select this jump button.

00:16.000 --> 00:17.400
Then go over to Inspector.

00:17.400 --> 00:18.480
Scroll down.

00:18.480 --> 00:21.080
We need to call the function right over here.

00:21.080 --> 00:23.760
So once we're going to click on this jump button.

00:23.760 --> 00:25.640
So we need to call the function here.

00:25.840 --> 00:29.760
And we do know that we have done inside our player skip.

00:29.960 --> 00:33.800
Uh basically we need to select our player game object in the hierarchy.

00:34.200 --> 00:39.000
So I'm going to select my player game object in the hierarchy I have it over here.

00:39.000 --> 00:41.480
So let's select that and let's open up the player.

00:41.480 --> 00:44.320
Skip in Inspector by double clicking on it.

00:44.760 --> 00:48.760
And if we scroll down we have the jump function.

00:48.800 --> 00:50.160
Something over here.

00:50.160 --> 00:50.960
We need to find it.

00:50.960 --> 00:54.240
So as you can notice we have it over here.

00:54.240 --> 00:59.320
And make sure you just mark your function as public so we can call through a button.

00:59.320 --> 01:04.570
So what we need to do we need to call the function uh we need to call this jump function.

01:04.770 --> 01:07.330
And what jump function is really doing.

01:07.370 --> 01:14.770
It's basically jumping our player, as you can notice in the y axis and basically in the y axis and

01:14.770 --> 01:15.490
in the zero.

01:15.610 --> 01:16.610
Uh sorry.

01:16.650 --> 01:18.210
In the x axis zero.

01:18.410 --> 01:19.930
So let's call the function.

01:19.930 --> 01:23.930
So let's move over to unity and let's select our jump button.

01:23.930 --> 01:28.770
So for that I'm going to move over to canvas UI and select this jump button.

01:28.770 --> 01:30.170
Let's go over to Inspector.

01:30.170 --> 01:32.810
Scroll down to the bottom says Button component.

01:32.810 --> 01:35.090
And let's click on this plus icon.

01:35.090 --> 01:39.650
So we need to drag the GameObject in which GameObject the script is sitting on.

01:39.650 --> 01:42.930
And we do know we have done inside our player script.

01:42.930 --> 01:49.170
So we're gonna drag our player GameObject right over here because the player script is sitting on our

01:49.170 --> 01:50.730
player GameObject.

01:50.730 --> 01:54.090
So I'm gonna move over to my other stuff.

01:54.090 --> 01:55.450
So I'm going to select my player.

01:55.490 --> 01:58.290
Let's drag it there and it says no function.

01:58.290 --> 01:59.610
So let's click on it.

01:59.610 --> 02:04.570
Let's go to Player script right over here in the bottom we can notice.

02:04.930 --> 02:09.620
And inside our player script, we can see we created the jump function.

02:09.620 --> 02:10.980
So we're going to choose that.

02:11.180 --> 02:12.700
So now we have chosen.

02:12.700 --> 02:18.740
So if we click on this play button and then try to click on this jump button, you will see our player

02:19.180 --> 02:19.820
game object.

02:19.820 --> 02:21.860
Just gonna jump right away.

02:22.500 --> 02:29.740
So uh, we're gonna basically as, as soon as we're gonna click on this jump button, we can just make

02:29.740 --> 02:30.420
the jump.

02:30.540 --> 02:34.380
So if I just click on this jump button, as you can notice, we're jumping.

02:34.380 --> 02:40.900
But the problem is that we can jump as many times we want, which we really don't want, and we do know

02:40.900 --> 02:42.540
we're doing inside that.

02:42.620 --> 02:50.660
Uh, basically our, uh, once we click on this space button on our keyboard, we basically making the

02:50.660 --> 02:51.020
jump.

02:51.020 --> 02:52.380
And there we checking.

02:52.380 --> 02:55.380
So instead of doing that we're going to do something else.

02:55.380 --> 03:01.180
So basically what we need to do we need to get out of play mode and then move over to player script.

03:01.180 --> 03:05.140
So over here as you can see we just making our jump.

03:05.140 --> 03:09.630
So before we jump we also want to check if we are grounded or not.

03:09.670 --> 03:14.310
If this player is touching the ground, then we want to jump.

03:14.350 --> 03:16.670
Else we're not gonna jump at all.

03:16.670 --> 03:23.630
And we do know that if we move over to our skip and then move over to our update function, uh, right

03:23.630 --> 03:24.350
over here.

03:24.390 --> 03:29.990
As you can notice, if we press down space key at the same time, total jump is zero.

03:30.030 --> 03:34.510
F basically means we have, uh, more than one jump.

03:34.670 --> 03:39.070
So instead of checking over here, we're going to check it there.

03:39.110 --> 03:41.310
So what we're going to do we're going to remove this.

03:41.470 --> 03:46.270
So let's remove this and also remove this total jumps right over here.

03:46.390 --> 03:49.590
And we're gonna do it inside our jump function.

03:49.750 --> 03:56.190
So before we jump what we want to check, we just want to check if our jump is greater than zero.

03:56.230 --> 03:57.550
If so we're going to check.

03:57.550 --> 03:59.150
So before we make our jump.

03:59.150 --> 04:01.950
So let's make first bracket and some curly brackets.

04:01.990 --> 04:04.030
So what we want to check over here.

04:04.030 --> 04:09.350
We basically want to check if our total jumps if it's greater than zero f.

04:09.350 --> 04:13.110
And we do know that in the start of the game we just doing it.

04:13.110 --> 04:17.910
So what we're going to do now, we're going to put this line of code by Ctrl X for cut.

04:17.950 --> 04:25.270
We're going to paste inside Ctrl B basically what we're doing, we instead of doing inside our uh input

04:25.270 --> 04:27.350
dot get space right over here.

04:27.390 --> 04:32.390
We basically doing here inside our jump function as you can notice.

04:32.550 --> 04:37.630
And after jumping what we need to do we need to subtract our total jumps.

04:37.630 --> 04:41.910
So we will subtract total jumps minus minus basically.

04:41.950 --> 04:43.390
So subtracting one.

04:43.590 --> 04:50.590
So before we jumping uh what we're doing we basically checking if our total jumps is greater than zero

04:50.630 --> 04:50.950
f.

04:51.110 --> 04:56.110
And in the start of the game we just set total jumps to two, something like that.

04:56.110 --> 05:00.710
And we do know that two is greater than zero f or one something like that.

05:01.190 --> 05:03.230
So the condition getting true.

05:03.230 --> 05:04.710
So that's why we're going to jump.

05:04.710 --> 05:08.150
And after jumping we just subtracting total jumps.

05:08.150 --> 05:12.760
And we do know that this total jumps somehow it's going to hit zero.

05:12.960 --> 05:20.080
And when it hits zero, if we move over to our update function when it is zero, it's ground is true.

05:20.080 --> 05:23.360
Basically means player basically standing on this ground.

05:23.400 --> 05:28.040
Then what we're doing, then we're setting total jumps again to our extra jumps.

05:28.040 --> 05:30.000
And by default we have set two.

05:30.160 --> 05:32.360
So this right over here total jumps.

05:32.360 --> 05:35.800
Getting one more time two and two is greater than zero.

05:36.080 --> 05:37.800
So the condition getting true.

05:37.800 --> 05:41.440
So that's why we will able to jump for the next time as well.

05:41.680 --> 05:46.120
And now what we need to do we need to press down Ctrl s to save our script.

05:46.120 --> 05:48.080
And now let's move over to unity.

05:48.400 --> 05:50.280
Basically we're doing the same things.

05:50.280 --> 05:57.880
And instead of doing if that if condition basically inside our update function, we basically turn inside

05:57.880 --> 05:59.680
our jump function.

05:59.680 --> 06:01.400
So basically that is the cool thing.

06:01.480 --> 06:08.280
Now even if we press down space key and also this jump button, it's going to do the same thing because

06:08.280 --> 06:10.400
we're doing inside jump function.

06:10.400 --> 06:11.280
So that's why.

06:13.080 --> 06:14.520
So let's have a look.

06:15.250 --> 06:16.650
So just wait a moment.

06:18.970 --> 06:23.330
So once our compilation is done, we can just check that out.

06:23.810 --> 06:28.330
So I'm going to click on this play button in the top in order to play our game.

06:28.330 --> 06:30.330
And let's have a look on this.

06:30.410 --> 06:34.650
So as soon as we're gonna click on this jump button we will be able to jump.

06:34.650 --> 06:42.370
And once we jump two times then we're not gonna jump at all until and unless we hit our ground one time.

06:42.370 --> 06:47.370
So if I just click on this jump button, as you can notice, we not able to jump anymore.

06:47.730 --> 06:54.330
Uh, basically we jumping three times, but more than three times we not able to do it and we able to

06:54.330 --> 07:01.010
do it once this player game object touching this ground then we just resetting total jumps to our extra

07:01.010 --> 07:01.450
jump.

07:01.730 --> 07:08.530
And if I do the same thing with my space key, we can see it's doing the same thing because we have

07:08.530 --> 07:11.370
done all of the things inside that jump function.

07:11.370 --> 07:12.410
So that's why.

07:12.730 --> 07:15.410
And we're gonna talk about this attack button.

07:15.410 --> 07:18.060
Now if I just left click on my mouse button.

07:18.060 --> 07:22.060
We can see we're just playing our attack animation for now.

07:22.060 --> 07:23.180
I'm gonna remove that.

07:23.180 --> 07:29.180
If I just click left mouse button, I don't want to play the attack animation, but if I click on this

07:29.220 --> 07:31.380
attack button then I want to do it.

07:31.380 --> 07:37.180
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

07:37.220 --> 07:44.860
our update function, where we basically playing our attack animation right over here, as you can notice.

07:44.860 --> 07:48.420
So I'm going to make this one comment by double forward slash.

07:48.420 --> 07:52.660
And we do know that the comments basically don't interrupt our code.

07:52.780 --> 07:58.020
And if I press down Ctrl s then move over to unity and then click on this play button.

07:58.020 --> 08:04.340
You will notice if we click the left mouse button, we're not going to able to play the attack animation

08:04.340 --> 08:05.660
clip anymore.

08:06.060 --> 08:13.300
Uh, so for testing purpose purpose I'm just doing that and we're gonna hook that with this attack button.

08:13.300 --> 08:18.620
So once we're gonna click on this attack button, I want to play the attack animation of this player

08:18.660 --> 08:19.550
game object.

08:19.550 --> 08:25.270
So if I just go add and then click on this play button and then try to click left mouse button, you

08:25.270 --> 08:29.670
will notice our player not gonna play attack animation at all.

08:29.870 --> 08:33.430
So for testing purposes I'm just doing that.

08:33.430 --> 08:37.710
But once we're gonna click on this attack button then we just want to do that.

08:37.710 --> 08:40.870
As you can notice, I'm just clicking the left mouse button.

08:40.870 --> 08:44.870
It's not playing the jump basically attack animation.

08:45.110 --> 08:52.110
But once we click on this, uh, you can simply say this attack button will not able to play our attack

08:52.110 --> 08:52.870
animation.

08:52.870 --> 08:58.150
So basically what we need to do, we need to hook this attack button with our attack animation.

08:58.150 --> 08:59.790
So let's get out of play mode.

09:00.110 --> 09:07.510
And for that we're gonna move over to our skip and let's move over to our play attack animation function

09:07.510 --> 09:08.510
where we made it.

09:08.510 --> 09:14.910
So right over here, as you can notice, we just, uh, we just, uh, made this function.

09:14.910 --> 09:21.190
And this function is responsible for playing our animation clip, as you can notice, which is attack

09:21.190 --> 09:23.320
one, attack two, and attack three.

09:23.560 --> 09:30.680
So we need to call this function through our attack button so we can see we just this function is marked

09:30.680 --> 09:31.800
as private.

09:31.800 --> 09:35.240
So what we want to do, we're going to make this function public.

09:35.240 --> 09:38.320
So we can call the function uh through our button.

09:38.320 --> 09:40.760
So let's mark this function as public.

09:40.920 --> 09:44.040
And now we're going to press down Ctrl s to save our script.

09:44.040 --> 09:45.920
And now let's move over to unity.

09:46.280 --> 09:52.880
And we're going to hook that play attack animation function basically that function with our attack

09:52.880 --> 09:53.320
button.

09:53.320 --> 09:55.480
So just let's have a look on that.

09:55.960 --> 10:00.600
So we're going to so we need to hook that function with our attack button.

10:00.960 --> 10:02.640
So just wait a little moment.

10:02.640 --> 10:07.480
And once we are done we can just hook that function with our attack button.

10:07.800 --> 10:10.400
So for that we're going to head over to hierarchy.

10:10.520 --> 10:14.160
Let's go to canvas UI and let's choose this attack button.

10:14.160 --> 10:15.560
Let's go over to Inspector.

10:15.560 --> 10:17.520
Scroll down to the button component.

10:17.520 --> 10:20.400
And we can notice on click and it's empty.

10:20.400 --> 10:22.320
So let's click on this plus icon.

10:22.320 --> 10:27.640
And we do know that we need to track the game object and which game object the script is sitting on.

10:27.640 --> 10:29.280
So in our case player.

10:29.280 --> 10:30.360
So let's select that.

10:30.360 --> 10:33.360
Let's drag it there and it says no function.

10:33.360 --> 10:37.320
So let's click there and we will move over to player script in the bottom.

10:37.320 --> 10:39.840
As you can see our player C class.

10:40.000 --> 10:46.120
And in there we created play attack animation function as you can notice right over here.

10:46.120 --> 10:47.400
So we're gonna choose that.

10:47.400 --> 10:54.360
And now as soon as we click on this button it's going to play our attack animation clip of this player

10:54.360 --> 10:55.160
game object.

10:55.160 --> 10:56.560
So let's check that out.

10:56.560 --> 11:00.920
So I'm going to click on this play button in the top in order to play our game.

11:00.920 --> 11:02.960
And let's take a look on this.

11:04.400 --> 11:12.400
So you're gonna see that as soon as we click on this attack button it's going to play our attack animation.

11:12.400 --> 11:17.960
So if I just click on this attack button, as you can see by now, we can notice that we're playing

11:18.000 --> 11:19.640
our attack animation.

11:19.640 --> 11:26.170
But if I click left mouse button we're not playing our, uh, attack animation at all since basins.

11:26.170 --> 11:33.130
We just, uh, we just comment that function once we click the left mouse button, which is, uh, that's

11:33.130 --> 11:34.770
why it's not interrupting.

11:34.770 --> 11:40.090
Basically not displaying our attack animation once we click our left mouse button.

11:40.090 --> 11:45.170
But once we click on this attack button, we can notice it's playing the attack animation.

11:45.170 --> 11:47.410
Basically, it's working fine.

11:47.530 --> 11:52.010
And we can just click on this right or left arrow to move left and right.

11:52.010 --> 11:56.130
And we can just click on this jump button to jump as you can notice.

11:56.130 --> 11:58.210
So basically it's working fine.

11:58.490 --> 12:00.450
And I hope you get the idea.

12:00.450 --> 12:05.610
And I'm gonna get out of play mode and make sure you just move over to your UI game object.

12:05.610 --> 12:11.850
Basically the parent one, if you turn it into a prefab then go over to Inspector Overrides and then

12:11.850 --> 12:12.770
apply all.

12:12.770 --> 12:19.130
So the changes you made inside this attack and this jump button is going to be saved into this UI GameObject

12:19.130 --> 12:20.890
prefab as well.

12:20.890 --> 12:28.650
So I hope you get the idea that how you can hook a function with a button with a button to do a specific

12:28.690 --> 12:29.330
things.
