WEBVTT

00:00.040 --> 00:03.560
Let's keep some health amount to our player game object.

00:03.560 --> 00:06.200
So let's select the player game object in the hierarchy.

00:06.360 --> 00:10.480
And let's open up the player script by double clicking on it in the inspector.

00:11.000 --> 00:12.120
So what we will do.

00:12.160 --> 00:16.480
We just going to give some health amount to our player game object.

00:16.680 --> 00:23.640
And we also need to make the Takedamage function in order to take damage from this enemy to or from

00:23.640 --> 00:26.560
this enemy to as well as enemy one.

00:26.560 --> 00:32.000
So just wait a moment and we will head over to our code as you can notice.

00:32.000 --> 00:37.680
So let's go to top of our class and let's do it over here somewhere over here.

00:37.680 --> 00:38.680
Let's do that.

00:38.920 --> 00:42.680
So what we will do we firstly let's give it a title.

00:42.680 --> 00:45.480
So we're going to make square brackets and then header.

00:46.160 --> 00:48.120
So let's make header.

00:48.760 --> 00:54.120
And let's say something like hell let's call it health health.

00:54.280 --> 00:59.720
And let's give some health amount to our uh our uh player game object.

00:59.720 --> 01:04.380
And this parameter does not need to be public, so we can make it private instead.

01:04.580 --> 01:08.180
So we can remove this health title as well.

01:08.460 --> 01:13.220
But let's keep that because we're going to use later on with UI.

01:13.260 --> 01:15.180
So that's why we're going to leave that.

01:15.260 --> 01:16.900
So let's make it private.

01:17.300 --> 01:21.580
A private int which can be basically 0123.

01:21.820 --> 01:28.500
And we will do the same thing as we have done with anime two script as well as anime one script in that

01:28.540 --> 01:30.540
health and damage scripting.

01:30.620 --> 01:32.740
So we're going to approach the same way.

01:33.140 --> 01:34.660
So let's give some health amount.

01:34.700 --> 01:38.060
So we're going to call it something like Max health.

01:38.300 --> 01:40.700
And let's set equal to something like five.

01:40.980 --> 01:43.100
And let's close that up with semicolon.

01:43.540 --> 01:44.700
And now what we will do.

01:44.740 --> 01:48.540
We're going to make the takedamage function in order to take the damage.

01:48.740 --> 01:53.900
And let's make it, uh, let's make it somewhere over here.

01:54.220 --> 01:58.660
And we're going to make this function public, since we're going to call this function from another

01:58.660 --> 02:00.570
class or another script.

02:00.570 --> 02:07.010
So that's why once our enemy two GameObject attack on our player GameObject at that moment, we're gonna

02:07.010 --> 02:07.570
call that.

02:07.570 --> 02:08.490
So that's why.

02:08.730 --> 02:10.610
So let's make this function public.

02:10.970 --> 02:14.690
For function we're going to type void and we have to name the function.

02:14.690 --> 02:17.090
So I'm going to call it take damage.

02:17.490 --> 02:19.170
Let's call it take damage.

02:19.170 --> 02:22.770
And it's going to take an argument which will be int.

02:22.770 --> 02:26.210
And we can call this one something like damage amount.

02:26.450 --> 02:31.410
And later on we're going to replace this damage amount with some real numbers.

02:31.410 --> 02:33.570
And let's make this curly brackets.

02:33.810 --> 02:37.610
So this will be int in type basically 01234.

02:37.650 --> 02:40.290
Or you can simply say whole numbers.

02:40.290 --> 02:43.290
So what we do what we're going to do right over here.

02:43.490 --> 02:46.090
We want to subtract our health amount.

02:46.090 --> 02:50.250
So before we subtract our health amount we need to check a check.

02:50.290 --> 02:54.450
If the max health of this player game object is already zero or not.

02:54.490 --> 02:59.150
If it is, then we need to stop damaging our player game object.

02:59.150 --> 03:01.710
So before we damage we just want to check.

03:01.910 --> 03:08.390
So if let's make first bucket and some curly brackets and what we want to check over here, we basically

03:08.390 --> 03:15.510
want to check if our back cell, if it's less than or equal to zero means our player game object don't

03:15.550 --> 03:18.830
have any health amount, it's totally zero.

03:18.990 --> 03:23.230
So in that moment what we need to do we need to stop damaging our player.

03:23.390 --> 03:25.430
So that's why we're going to type return.

03:25.430 --> 03:31.350
And we do know that after return, whatever we're gonna do it's not going to be execute at all.

03:31.350 --> 03:36.670
But let's suppose uh player game object has uh have some health amount.

03:36.670 --> 03:42.350
So else if our player game object has uh, have some health amount.

03:42.470 --> 03:49.230
So in that moment, what we need to do, we need to subtract them from our max cell, this damage amount.

03:49.230 --> 03:51.790
So let's subtract from this max cell.

03:51.830 --> 03:54.910
So max health minus equal damage amount.

03:55.710 --> 03:57.790
And then close that up with semicolon.

03:57.790 --> 03:57.900
column.

03:58.060 --> 04:02.660
So let's suppose we call this take demand function for the first time and max health.

04:02.660 --> 04:07.860
If we go to the top of our class, we have given five, as you can see right over here.

04:08.100 --> 04:12.260
So this Maxwell right over here, it's gonna five in the start of the game.

04:12.420 --> 04:15.860
And let's suppose we call this Takedamage function for the first time.

04:16.700 --> 04:19.020
So this max health is five.

04:19.140 --> 04:22.380
And let's assume this damage amount we pass one.

04:22.380 --> 04:24.740
So five minus one gonna be four.

04:24.900 --> 04:28.260
And if we call this second time this takedamage function.

04:28.260 --> 04:30.020
So the max is now four.

04:30.020 --> 04:32.220
So four minus one it's gonna be three.

04:32.340 --> 04:35.460
And if we call this take damage function for the third time.

04:35.460 --> 04:37.340
So the max health is now three.

04:37.340 --> 04:38.500
So three minus one.

04:38.500 --> 04:40.380
Just gonna be two as.

04:40.420 --> 04:46.740
And if we call this a fourth time, then this max health is two.

04:46.860 --> 04:48.900
So two minus one gonna be one.

04:48.900 --> 04:55.420
And if we call this takedamage function for the fifth time or five fifth time, then this max health

04:55.420 --> 04:55.940
is one.

04:55.940 --> 04:58.040
So one minus one is zero.

04:58.040 --> 05:03.160
So somehow our max health of of our player game object just gonna hit zero.

05:03.280 --> 05:09.360
So in that moment, what we need to do, we need to make the die function in order to destroy our player

05:09.400 --> 05:10.120
game object.

05:10.160 --> 05:15.280
For now, we're gonna print out a message, and we're gonna make the function in the bottom somewhere

05:15.280 --> 05:16.120
over here.

05:16.280 --> 05:18.280
So for function, we're going to type void.

05:18.320 --> 05:19.840
And we have to name the function.

05:19.840 --> 05:21.080
So I'm going to call it die.

05:21.240 --> 05:24.000
Let's make first bracket and some curly brackets.

05:24.080 --> 05:29.360
So what we want to do for now we just want to print out the message for now.

05:29.360 --> 05:33.040
And later on we're gonna destroy our player game object.

05:33.160 --> 05:36.120
So printing out message we're going to type debug.log.

05:36.240 --> 05:39.800
And we will say something like this dot.

05:39.880 --> 05:49.920
So we will say this dot sorry this dot game object dot name, dot sorry dot name.

05:49.920 --> 05:52.520
And top of that I'm gonna add a custom message.

05:52.520 --> 05:55.120
So let's use this plus icon and quotation.

05:55.280 --> 05:59.510
I'm gonna say something like diet and let's close that up with semicolon.

05:59.510 --> 06:00.470
So this dot game.

06:00.510 --> 06:04.870
Object dot name basically it just referencing and we accessing the name.

06:04.870 --> 06:07.830
And we can see the name is player in inspector.

06:07.830 --> 06:08.630
We can see.

06:08.830 --> 06:12.710
So over here this dot game object dot name just gonna be player.

06:12.870 --> 06:15.870
And top of that we added a message says tired.

06:15.870 --> 06:18.190
So this message should be pop up player died.

06:18.230 --> 06:21.390
Message should be pop up in our console tab.

06:21.550 --> 06:23.990
And we also need to call this die function.

06:23.990 --> 06:30.750
So when we need to call this die function, once our player game object loses off all of his health.

06:30.790 --> 06:38.590
And over here, as you can see, if the max health is already lesser than or equal to zero means our

06:38.590 --> 06:41.230
player game object just loses all of his health.

06:41.230 --> 06:43.950
So now we can call the die function here.

06:43.950 --> 06:46.590
So before we return, we're going to call the die function.

06:46.590 --> 06:52.550
If our max cell of our player game object is already became zero or less than zero.

06:52.550 --> 06:54.430
So let's call the die function here.

06:54.670 --> 06:56.890
And what this dysfunction just gonna do?

06:56.930 --> 06:58.530
It's gonna print out the message.

06:58.530 --> 07:04.170
As you can see, this dot game object dot name, basically the name of the game object and the name

07:04.170 --> 07:06.090
of the game object is player.

07:06.090 --> 07:09.450
And top of that we added a custom message say style.

07:09.490 --> 07:13.290
So player type message should be pop up in our console tab.

07:13.450 --> 07:16.650
And now we're gonna press down Ctrl S to save our script.

07:16.810 --> 07:22.530
And we also need to call that Takedamage function as we created inside our player game object.

07:22.530 --> 07:23.730
So we need to call.

07:23.770 --> 07:26.730
But before we call it make sure you save your script.

07:27.010 --> 07:32.530
So I'm gonna say I'm gonna press down Ctrl s on my keyboard in order to save my script.

07:33.730 --> 07:37.290
Let's press down Ctrl S and let's move over to unity.

07:37.690 --> 07:45.010
So as soon as our script just gonna compile it, we will open up our animator script, basically where

07:45.010 --> 07:46.770
we just printing out the message.

07:46.930 --> 07:51.970
And before we call the Takedamage function, let me show you what we simply doing.

07:52.290 --> 07:58.960
So we will select our console tab and we will, uh, click the play button in the top in order to play

07:58.960 --> 07:59.760
our game.

08:00.280 --> 08:02.520
So now let's wait a few seconds.

08:02.840 --> 08:05.400
The compilation is done by now.

08:06.440 --> 08:07.800
So now it's done.

08:08.000 --> 08:11.800
So let's select the console tab console tab over here.

08:11.960 --> 08:16.080
And let's click on this play button in the top in order to play our game.

08:16.400 --> 08:22.360
And you will see as soon as our anime two game object just gonna attack on this player game object.

08:22.360 --> 08:29.160
The message just gonna pop up as a player takes damage and instead of printing out message, we basically

08:29.160 --> 08:32.440
need to call the Takedamage function from this player's game.

08:32.480 --> 08:35.920
Or you can simply say from this player game object.

08:35.920 --> 08:37.960
So let's see before we damage it.

08:38.360 --> 08:45.560
So let's say as you can notice that the message just getting pop up whenever this enemy two game object

08:45.600 --> 08:48.720
attacking on our player game object.

08:48.720 --> 08:52.680
So instead of printing out message, we're gonna call the Takedamage function.

08:52.680 --> 08:54.380
So let's get out of play mode.

08:54.380 --> 08:59.140
And let's double click on this message in order to move over to that line of code.

08:59.140 --> 09:03.020
So I'm going to double click on it in order to move over to that line of code.

09:03.140 --> 09:04.180
So just wait.

09:04.340 --> 09:07.740
So over here as you can see we printing out message.

09:07.740 --> 09:13.060
So instead of printing out message we're going to call the Takedamage function from our player skip.

09:13.300 --> 09:16.860
So we basically need to go over to this player skip.

09:16.900 --> 09:20.060
And then we need to call this Takedamage function.

09:20.060 --> 09:21.340
So let's call that.

09:21.340 --> 09:23.100
So let's go to animator script.

09:23.100 --> 09:26.420
So instead of printing out message so let's remove that.

09:26.740 --> 09:31.420
We will use this call info call info dot GameObject dot.

09:31.660 --> 09:35.660
Uh we want to get the component and the component is player skip.

09:35.660 --> 09:38.060
So we're going to use this dot get component.

09:38.060 --> 09:43.220
Then make this first bracket and the component we're looking for or the script that we're looking for

09:43.260 --> 09:44.060
is player.

09:44.060 --> 09:50.860
So I'm going to type this player, uh sorry uh type this player and then make this first bracket.

09:50.860 --> 09:53.560
So we do know that inside that player players keep.

09:53.560 --> 09:56.200
We created the Takedamage function.

09:56.200 --> 09:57.080
So after making.

09:57.120 --> 09:58.720
First bracket we're going to call the.

09:58.920 --> 10:01.480
We're going to access the Takedamage function.

10:01.480 --> 10:03.920
So let's type this dot takedamage.

10:04.000 --> 10:08.760
And let's make first bracket and then close that up with semicolon and take damage.

10:08.760 --> 10:12.760
As you can see it's gonna take the argument which is damage amount.

10:12.920 --> 10:15.040
So if we put five right away.

10:15.480 --> 10:20.880
So if we put five then our player GameObject just gonna die right away.

10:20.880 --> 10:26.040
Since we have given as five unit of health to our player game object.

10:26.040 --> 10:28.760
So that's why it's gonna die right away.

10:29.000 --> 10:35.680
But instead of damaging, right, basically destroying our player game object, we're gonna put one.

10:35.680 --> 10:42.920
So every single time we just gonna attack on our player game object, we will use one unit of health.

10:42.920 --> 10:49.480
So that's why as a damage team, as a damage amount or damage amount argument, I just pass one.

10:49.480 --> 10:54.350
So call info dot GameObject basically means the game object the circle collided with.

10:54.350 --> 10:59.750
So the circle that we created inside this enemy two game object, it's gonna collide with this player

10:59.790 --> 11:00.710
game object.

11:00.710 --> 11:06.790
So that's why this call info dot game object basically means that player game object and you we using

11:06.790 --> 11:10.110
this dot get component in order to get the component.

11:10.110 --> 11:12.470
And the component we are looking for is player.

11:12.470 --> 11:18.350
So simply we just going over to this player game object and then going over to this player escape.

11:18.390 --> 11:22.190
And from this player escape we just calling the Takedamage function.

11:22.190 --> 11:25.670
And we do know what this Takedamage function is really doing.

11:25.710 --> 11:28.550
It's basically subtracting our health.

11:28.950 --> 11:35.270
But before it subtract, we just checked if the max health of our player game object is already zero

11:35.270 --> 11:35.750
or not.

11:35.790 --> 11:40.150
If it's a then we just calling the die function and we stop.

11:40.510 --> 11:44.270
We stop subtracting our damage.

11:44.790 --> 11:49.350
Basically, we just stop damaging our are basically taking damage.

11:49.350 --> 11:51.110
We just stopping that.

11:51.110 --> 11:57.050
And now we're going to press down control S in our anime to skip in order to save our skip.

11:57.090 --> 11:58.850
And let's head over to unity.

11:59.050 --> 12:06.170
So as soon as we the the compilation just gonna turn and then anime to game object just gonna place

12:06.170 --> 12:10.770
the attack animation and it's just going to attack on our player game object.

12:10.770 --> 12:16.010
We will able to notice a player health just gonna shrink down to one.

12:17.250 --> 12:19.730
Uh, but we're not gonna able to notice that.

12:19.770 --> 12:20.210
Why?

12:20.370 --> 12:21.730
Because we maxhealth.

12:21.970 --> 12:28.370
We made that parameter private, so that's why we not able to notice underneath our player skip, as

12:28.370 --> 12:29.130
you can see.

12:29.290 --> 12:30.810
But we still want to see.

12:30.810 --> 12:32.890
So we need to move over to debug mode.

12:32.930 --> 12:34.650
To do so go over to Inspector.

12:34.650 --> 12:36.690
In the top right you can see three button.

12:36.690 --> 12:39.570
So just click there and then choose this debug.

12:39.570 --> 12:46.610
And as soon as we have chosen debug by now we can see the max health is five over here as you can notice.

12:46.610 --> 12:50.770
So let's click on this play button in the top in order to play our game.

12:50.800 --> 12:58.640
So, uh, so, uh, what basically, uh, enemy two game object need to, uh, damage our player game

12:58.680 --> 13:03.720
object five times or basically need to attack on our player game object five times.

13:03.960 --> 13:09.600
Uh, so once our max health of this player just gonna reach zero, you will see the message just gonna

13:09.600 --> 13:11.400
pop up in our console tab.

13:11.400 --> 13:15.600
And indeed, we can see it's became two, then one and then zero.

13:15.840 --> 13:18.320
But still the message is not getting pop up.

13:18.320 --> 13:24.280
But once it hits one more time, basically this enemy two game object, uh, attack on this player game

13:24.320 --> 13:29.640
object for the sixth time, we can see the message just getting pop up in our console tab.

13:29.800 --> 13:30.760
Player died.

13:30.760 --> 13:34.720
So instead of checking with zero, we're gonna check with one.

13:34.720 --> 13:36.120
Since this enemy.

13:36.560 --> 13:39.520
Enemy two game object, uh, damaging our player.

13:39.560 --> 13:46.680
Basically, it's taking six time in order to damage our basically to loses all of his all of this,

13:46.880 --> 13:51.260
uh, to lose all of his health of this player game object.

13:51.260 --> 13:56.460
So let's get out of play mode and we're gonna move over to script one more time.

13:56.460 --> 14:00.460
So instead of checking with zero, we're going to check with, uh, one.

14:00.700 --> 14:01.300
Sorry.

14:01.340 --> 14:03.620
We will move over to our player script.

14:03.860 --> 14:06.420
So as you can see we're checking with zero.

14:06.420 --> 14:09.420
So instead of checking with zero we're going to pass one.

14:09.420 --> 14:15.340
So now the max health is just going to be uh, so the max health of our player game object.

14:15.340 --> 14:18.860
If it hits zero then the die function is just going to call out.

14:18.860 --> 14:22.500
And what die function is really doing is just printing out the message.

14:22.540 --> 14:25.220
Uh, the message says player die.

14:25.260 --> 14:31.420
As you seen underneath our console tab, we can see player type message just gets pop up as soon as

14:31.460 --> 14:34.660
this player game object loses all of his health.

14:34.660 --> 14:37.860
And now we're going to press down one more time to, uh, one more time.

14:38.100 --> 14:41.140
Uh, control is to save our script before we do.

14:41.300 --> 14:46.620
So once we, uh, loses all of his health, as you can see, we're doing over here.

14:46.780 --> 14:48.980
And then we're calling the die function.

14:48.980 --> 14:52.410
So we also want to set the max health to zero.

14:52.650 --> 14:58.810
So so in the UI, just gonna show up that the max health of this player game object is zero.

14:59.090 --> 15:06.410
So once our max health max health of this player game object hit zero, we also want to set the max

15:06.410 --> 15:08.570
health of this player game object to zero.

15:08.730 --> 15:12.170
So what we will do we will set max health equal to zero.

15:12.450 --> 15:19.210
And because we're going to show up in the UI and you will understand later on so that we just set the

15:19.210 --> 15:21.930
Maxwell equal to zero as you can notice.

15:22.130 --> 15:28.370
And if we just don't do it and then go and then press down control S to set our skip and then move over

15:28.370 --> 15:31.090
to unity, you're gonna get an bug.

15:31.250 --> 15:32.370
Let me show you that.

15:32.370 --> 15:36.370
So that is the reason we need to set the max health to zero.

15:36.650 --> 15:41.250
So before we set it to zero, let me show you what's gonna happen.

15:41.690 --> 15:48.830
So this enemy two game object, this enemy two game object need to damage our player five times in order

15:48.830 --> 15:54.710
to lose all of, uh, all of this, all of his health of this player game object.

15:55.270 --> 16:00.270
You will see as soon as our player game object just loses all of his health.

16:00.310 --> 16:06.510
The message just gonna pop up in our console tab says player died because we're calling the die function.

16:06.510 --> 16:09.950
Once our player game object loses all of its health.

16:10.110 --> 16:12.590
So the Maxwell by default we can see five.

16:12.630 --> 16:16.630
So let's click on this play button in the top in order to play our game.

16:17.030 --> 16:18.830
And we will notice that.

16:18.830 --> 16:24.270
And if you just want to go over to Inspector mode then you can just go over to top right one more time.

16:24.270 --> 16:27.790
Then click on that three dots and then click on that normal.

16:27.790 --> 16:30.070
So you can go back to normal mode.

16:30.550 --> 16:32.750
And the max health we can see five.

16:32.750 --> 16:39.670
And if this enemy attacks we can see it's it's becoming four then three and then one.

16:39.910 --> 16:43.270
And then it's becoming it's becoming zero.

16:43.470 --> 16:47.550
But as you can see Maxwell is is stuck at one.

16:47.550 --> 16:53.980
So that is why once this anime sorry, once this player game object loses all of his health basically

16:53.980 --> 16:58.340
fifth time, then we also want to set back this max health to zero.

16:58.380 --> 17:05.380
Once our player game object loses all of his health, basically this anime to game object needs a five

17:05.420 --> 17:12.700
times in order to damage or damage or to destroy our player game object or to call the die function.

17:12.700 --> 17:20.940
So this anime game object need to need to play the need to play five times of attack animation clip

17:20.980 --> 17:23.140
and this anime to game object.

17:23.140 --> 17:24.700
So let's get out of play mode.

17:24.700 --> 17:27.860
So that's why we're gonna set back this max health to zero.

17:28.020 --> 17:30.540
So we will move over to script one more time.

17:30.540 --> 17:36.140
So once we call the die function, after calling that I function, I just want to set the max health

17:36.140 --> 17:41.020
to zero, as using the max health just gets a stack at one, so that's why.

17:41.180 --> 17:44.020
So we will set max health equal to zero.

17:44.180 --> 17:46.340
And let's close that up with semicolon.

17:46.340 --> 17:49.160
And we're going to press down Ctrl S to save our script.

17:49.200 --> 17:51.040
And now let's move over to unity.

17:51.160 --> 17:58.440
So as soon as our our player GameObject takes damage for five times, it's gonna lose all of his health.

17:58.440 --> 18:04.160
And you will see, after losing all of his health, this Max health just gonna set back to zero.

18:04.440 --> 18:08.440
And we're setting it to zero because we need to show up in the UI.

18:08.480 --> 18:12.120
So that's why we're just doing that inside our code.

18:12.360 --> 18:14.200
And now let's play the game.

18:14.400 --> 18:16.560
And let's take a look on this.

18:16.640 --> 18:22.920
So as soon as this player GameObject a max health reaches zero, that function just gonna call, which

18:22.920 --> 18:25.000
is the die function and die function.

18:25.000 --> 18:29.720
Simply printing out the message in our console tab says player died.

18:30.120 --> 18:37.600
And this enemy two GameObject need to damage our player GameObject five times, or it's need to attack

18:37.640 --> 18:38.240
five times.

18:38.240 --> 18:39.000
We can see.

18:39.360 --> 18:39.720
So.

18:39.720 --> 18:41.600
So the max health is became one.

18:41.600 --> 18:46.670
And as you can see, as soon as this player GameObject loses all of his health.

18:46.670 --> 18:53.110
We can see in our console tab the message just getting pop up saying player died and the message just

18:53.110 --> 19:01.110
getting a pop up over again and again once this enemy to game object attacking on this player game object.

19:01.110 --> 19:04.190
Since this player game object loses all of his health.

19:04.230 --> 19:04.910
That's why.

19:05.070 --> 19:07.350
And we can see the max health is zero.

19:07.350 --> 19:08.870
So I'm gonna get out of play mode.

19:08.870 --> 19:14.790
So I hope you get the idea that how you can make the Takedamage function, and how you can give some

19:14.790 --> 19:17.190
health amount to your player game object.

19:17.190 --> 19:25.350
So we basically have done the same thing as we have, as we already done with our enemy one and enemy

19:25.390 --> 19:26.950
two script earlier.

19:27.230 --> 19:31.030
So we also need to call the function with our enemy one.

19:31.990 --> 19:34.070
So we need to do that.

19:34.070 --> 19:37.110
And let's suppose you just want to go back in normal mode.

19:37.150 --> 19:41.190
You don't want to see this max health and this private parameters.

19:41.190 --> 19:46.450
Then go over to Inspector one more time and it's gonna say something like debug In the top right you

19:46.450 --> 19:47.450
can see three dots.

19:47.450 --> 19:50.170
So just click there and then click on this normal.

19:50.170 --> 19:54.010
So you will go back to Inspector mode or normal mode.

19:54.010 --> 19:57.010
And now we have to deal with our enemy one.

19:57.010 --> 20:00.050
So I'm going to select my enemy to GameObject in the hierarchy.

20:00.090 --> 20:02.690
Let's go over to Inspector and we're gonna uncheck.

20:02.730 --> 20:08.610
Basically you can simply say we just disabling that and I'm gonna select my enemy one GameObject in

20:08.610 --> 20:09.410
the hierarchy.

20:09.410 --> 20:12.890
And we can check this to enable or what else you can do.

20:12.930 --> 20:18.410
You can just go over to your project tab, a project tab assets and then prefabs folder.

20:18.450 --> 20:26.210
Basically move over to move over to that folder in which folder you just made your enemy one GameObject

20:26.210 --> 20:27.330
as prefab.

20:27.330 --> 20:30.890
So make sure you you turn your game object into prefab.

20:30.890 --> 20:32.370
So you're gonna have to copy.

20:32.570 --> 20:34.290
And later on you can do so.

20:34.290 --> 20:37.930
Just move over to that folder and then select your enemy.

20:38.490 --> 20:39.250
Enemy one.

20:39.290 --> 20:42.250
Drag it over to the scene view or into this hierarchy.

20:42.290 --> 20:49.470
I'm not gonna do it again because I already have have a anime one game object in my scene view as well

20:49.470 --> 20:51.190
as in the hierarchy, so that's why.

20:51.590 --> 20:56.990
And now let's test with this, uh, test with this, uh, you can simply say this anime one.

20:56.990 --> 21:01.230
So let's click on this play button in the top in order to play our game.

21:01.230 --> 21:06.590
And we do know that as soon as the arrow collide with this player game object, the message just getting

21:06.590 --> 21:10.190
pop up in the console says, uh, player takes damage.

21:10.190 --> 21:15.110
So instead of printing out message, we're gonna call the take damage from Takedamage function from

21:15.110 --> 21:16.270
this player's game.

21:16.310 --> 21:20.670
Basically, we're gonna do the same thing as we have done with our enemy two.

21:21.070 --> 21:25.350
Basically, uh, we have done recently, uh, the process.

21:25.350 --> 21:26.350
So let's get in.

21:26.390 --> 21:30.190
We can see if we move over to my console tab.

21:30.870 --> 21:34.790
As you can see, the messages getting pop up player takes damage.

21:34.790 --> 21:37.670
So instead of printing out message, what we gonna do?

21:37.790 --> 21:40.830
Uh, we're gonna call the takedamage function from this player.

21:40.830 --> 21:41.310
Skip.

21:41.310 --> 21:46.660
So let's get out of play mode, and let's double click on this message in order to move over to that

21:46.660 --> 21:47.500
line of code.

21:47.660 --> 21:49.260
So let's double click on it.

21:49.780 --> 21:54.660
And so over here, as you can see we just simply printing out message.

21:54.740 --> 22:00.580
So instead of printing out message we need to call the function Takedamage function from our player

22:00.580 --> 22:00.980
scape.

22:01.020 --> 22:07.660
So we're going to remove this message and we will use this collision dot GameObject dot get component

22:07.660 --> 22:09.220
basically doing the same thing.

22:09.420 --> 22:13.500
And the component we're looking for is a player or player C script.

22:13.500 --> 22:17.340
So we're going to pass that the component and then make this first bracket.

22:17.460 --> 22:20.300
And we're going to call the Takedamage function by now.

22:20.300 --> 22:24.660
So let's type this dot and then take damage and make first bracket.

22:24.660 --> 22:28.140
And inside this first bracket it's going to take the damage amount.

22:28.140 --> 22:29.740
So I'm going to pass one.

22:29.740 --> 22:36.900
And if you pass a five or some bigger value then our player GameObject just gonna die right away.

22:36.900 --> 22:38.460
And I don't want to do that.

22:38.460 --> 22:42.780
So that's why I just pass a pass as a damage amount one.

22:42.940 --> 22:45.200
And we're going to close that up with semicolon.

22:45.240 --> 22:51.160
Firstly what we're doing, we're just checking if the basically if our arrow game object collided with

22:51.200 --> 22:53.040
the player game object or not.

22:53.160 --> 22:58.400
So this function get called when we trigger with something and we're checking if the trigger is player.

22:58.440 --> 23:05.200
Basically collision dot game object means the game object arrow triggered with and we accessing the

23:05.200 --> 23:11.080
tag of it, and we checking if the tag is equals equals to player basically means with the arrow just

23:11.080 --> 23:13.760
triggering with our player game object.

23:13.760 --> 23:18.200
Or you can simply say player arrow just colliding with our player game object.

23:18.240 --> 23:23.320
Then what we're doing, we're just going over to player game object collision game object over here

23:23.320 --> 23:26.480
basically means the game object the arrow trigger it with.

23:26.480 --> 23:29.600
So arrow gonna trigger with that player game object.

23:29.600 --> 23:33.040
So collision dot game object over here just gonna be player.

23:33.040 --> 23:35.400
And then we're just going to player game object.

23:35.400 --> 23:40.600
And we just going over to player script or we just getting the player script.

23:40.600 --> 23:45.270
And from that player script we're recalling the Takedamage function as you can notice.

23:45.270 --> 23:48.710
So basically we're just going over to this player GameObject first.

23:48.710 --> 23:50.510
And we just getting this player script.

23:50.550 --> 23:52.590
As you can see in the inspector.

23:52.590 --> 23:55.670
And from this player script we're calling the Takedamage function.

23:55.710 --> 23:59.790
Basically this function and we do know what this function is really doing.

23:59.830 --> 24:06.070
It's basically subtracting max health uh by this amount of damage amount.

24:06.270 --> 24:07.910
So I hope you get the idea.

24:07.910 --> 24:10.230
And we need to save our script.

24:10.230 --> 24:12.950
So let's press down Ctrl s to save our script.

24:12.950 --> 24:14.790
And now let's move over to unity.

24:15.110 --> 24:21.590
And we we will see as soon as arrow just gonna trigger with this player GameObject or just gonna collide

24:21.590 --> 24:23.110
with this player GameObject.

24:23.110 --> 24:27.390
Then this player GameObject just gonna loses his health.

24:27.590 --> 24:32.750
His health by one unit since we pass our damage amount as one.

24:32.750 --> 24:33.510
So that's why.

24:33.950 --> 24:35.830
So let's have a look on this.

24:36.230 --> 24:40.070
So firstly we need to get closer to this enemy one game object.

24:40.070 --> 24:45.250
I'm going to select that anime one GameObject in the hierarchy in order to see the circle.

24:45.530 --> 24:48.050
And let's click on this play button in the top.

24:48.210 --> 24:48.570
So.

24:49.170 --> 24:55.650
So if the arrow hit five times, uh, five times with this player game object, uh, so it's gonna lose

24:55.650 --> 24:57.210
all of his health and we don't know.

24:57.210 --> 24:59.770
We're calling the die function and die function.

24:59.770 --> 25:04.250
Printing of the message in the console says, uh, die, which is player die.

25:04.290 --> 25:06.250
So let's get in attack range.

25:06.410 --> 25:09.530
And we can see indeed it's taking damage.

25:09.530 --> 25:15.170
And once it loses all of its health, we can see underneath our console tab message.

25:15.210 --> 25:17.610
Just getting pop up says player died.

25:17.770 --> 25:20.650
So I hope you get the idea that how you can do it.

25:20.690 --> 25:22.890
And I'm gonna get out of play mode.

25:23.610 --> 25:24.490
Uh, play mode.

25:24.730 --> 25:28.290
Uh, but, uh, we gonna make that, uh, player health public.

25:28.530 --> 25:29.010
Why?

25:29.410 --> 25:34.850
Uh, because we just want to adjust our player health in, uh, in the inspector.

25:34.850 --> 25:41.920
So that's why we're going to mark that, uh, mark that parameter, uh, as serialized fail instead

25:41.920 --> 25:43.600
of making private.

25:43.600 --> 25:50.120
I really apologize for that because I didn't get you through that, so I really apologize.

25:50.200 --> 25:56.440
So what we're gonna do, we're gonna mark that function as a serialized field so we will able to notice

25:56.440 --> 26:02.280
underneath our player skip, so we can adjust the max health of this player game object.

26:02.280 --> 26:03.960
So basically that is the thing.

26:03.960 --> 26:07.360
So we will open up our player skip by double clicking on it.

26:07.560 --> 26:13.920
And let's go to top of our class where we declare the variable Max health over here as you can see.

26:13.920 --> 26:16.360
So we're going to mark this function as serialized field.

26:16.360 --> 26:18.960
So we can see underneath our player skip.

26:18.960 --> 26:21.920
And we can adjust the adjust the max health.

26:22.120 --> 26:22.880
Uh there.

26:23.120 --> 26:27.720
So we're going to mark this uh parameter as serialized field.

26:27.920 --> 26:29.320
And now we're going to close that.

26:29.360 --> 26:32.360
We're going to press down control S to save our skip.

26:32.360 --> 26:34.480
And now let's move over to unity.

26:34.480 --> 26:38.160
So basically we mark this function as a serialized field.

26:38.160 --> 26:44.900
So we can see underneath our players grip, and we can just adjust it over here so we don't need to

26:44.900 --> 26:46.300
go over to that script.

26:46.380 --> 26:53.140
Basically inside our player script and change the maxhealth value over again and again to just get the

26:53.140 --> 26:53.940
correct one.

26:53.940 --> 26:56.860
So that's why we just marked as Celia.

26:56.860 --> 27:02.580
And we can see health and by default we have this five.

27:02.780 --> 27:08.220
And we need to move this move speed into our player jump title section.

27:08.220 --> 27:08.620
Why?

27:08.780 --> 27:11.820
Because this move speed doesn't match with our health.

27:11.820 --> 27:13.260
So that's why we're gonna move.

27:13.340 --> 27:16.820
Move this move speed parameter inside this player jump.

27:16.820 --> 27:20.820
Or we can simply create another title for this as well.

27:20.820 --> 27:22.060
So let's do that.

27:22.060 --> 27:29.180
So I'm going to open up my player script and let's go over to uh, before we, uh, just before we,

27:29.580 --> 27:31.780
um, split our move speed.

27:31.820 --> 27:33.140
Let's give it a title.

27:33.300 --> 27:39.260
So let's make this square brackets then header, and we're going to say something like, uh movement.

27:39.570 --> 27:42.410
So let's give it a title, which is movement.

27:42.570 --> 27:49.370
And if we press down control S and then move over to script and sorry move over to unity editor, we're

27:49.370 --> 27:52.090
going to see a new title for this move, speed.

27:52.130 --> 27:56.410
And the title we have given the name is movement.

27:56.410 --> 28:01.490
So you can just put this inside this player jump title right over here.

28:01.690 --> 28:05.410
Or you can just create a separate title for this move speed.

28:05.690 --> 28:08.130
And we have done it already.

28:08.130 --> 28:12.930
So we can see by now we have a movement title and the move speed parameter.

28:12.930 --> 28:15.930
And we also have the health title and the Maxwell.

28:15.930 --> 28:18.770
And we can adjust the max health right over here.

28:18.770 --> 28:24.050
So we don't need to go to the script and change this value over again and again.

28:24.050 --> 28:31.010
So that's why we just mark that this parameter as public so we can adjust underneath our player scape.

28:31.010 --> 28:34.090
So I hope you get the idea that how you can do it.

28:34.090 --> 28:39.370
And I'm gonna press Ctrl s on my keyboard in order to save my project.
