WEBVTT

00:00.040 --> 00:03.720
Let's keep health amount to this enemy pawn game object.

00:03.720 --> 00:09.280
So let's select the enemy one game object in the hierarchy, and let's open up the enemy one script

00:09.280 --> 00:10.920
by double clicking on it.

00:10.920 --> 00:13.040
And let's go to top of our class.

00:13.040 --> 00:16.480
And let's declare a variable for our Maxell.

00:16.640 --> 00:20.560
So we will scroll up and let's make it over here.

00:21.120 --> 00:22.920
Uh, let's make it here.

00:22.920 --> 00:29.200
So just wait and let's give it a title before we create the variable or declare the variable.

00:29.200 --> 00:31.560
So let's give a header header.

00:31.600 --> 00:33.800
Sorry we're going to give a header.

00:33.800 --> 00:36.760
So let's make this square brackets header.

00:36.920 --> 00:40.320
And we're going to say something like health uh health.

00:40.360 --> 00:42.880
And let's create a serialized field.

00:43.440 --> 00:46.960
So let's create a serialized field private.

00:47.320 --> 00:49.120
And this will be int.

00:49.120 --> 00:52.200
And we can call this one something like Max health.

00:52.520 --> 00:56.600
And by default I'm going to give something around three unit of health.

00:57.040 --> 01:01.180
And now we're gonna make a function in order to take damage.

01:01.180 --> 01:04.260
And let's make it in the bottom somewhere over here.

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

01:09.100 --> 01:11.020
class or another script.

01:11.020 --> 01:15.340
So that's why for so let's mark this function as public.

01:15.540 --> 01:17.700
And for function we're going to type void.

01:17.740 --> 01:19.220
And we have to name the function.

01:19.220 --> 01:21.940
So let's call it something like take damage.

01:22.420 --> 01:23.660
Let's call it take damage.

01:23.660 --> 01:26.540
Let's make first bracket and some curly brackets.

01:26.700 --> 01:28.260
And this take damage function.

01:28.260 --> 01:30.220
Just going to take an argument.

01:30.220 --> 01:34.060
And that will be in type like whole number 01234.

01:34.060 --> 01:38.340
And we can call this one amount a amount something like that.

01:38.380 --> 01:41.140
Let's call it instead damage amount.

01:41.300 --> 01:44.140
So let's call it damage amount.

01:44.540 --> 01:50.020
And later on we're going to replace this damage amount with real numbers like 1234.

01:50.460 --> 01:52.780
But I'm going to test with one.

01:52.780 --> 01:55.940
So now what we basically have to do inside that function.

01:56.100 --> 02:00.450
We basically need to subtract from this max health by that damaged amount.

02:00.690 --> 02:02.090
So let's do that.

02:02.090 --> 02:04.130
So we will subtract from our max.

02:04.370 --> 02:08.050
So max minus equivalent in order to subtract that.

02:08.050 --> 02:11.410
And we just want to subtract with our damage amount.

02:11.410 --> 02:13.410
And let's close that up with semicolon.

02:13.970 --> 02:15.690
So now this finds.

02:15.690 --> 02:19.370
So let's suppose we call this takedamage function for the first time.

02:19.370 --> 02:21.970
So the max health by default we have given three.

02:22.010 --> 02:24.850
And let's assume this damage amount we pass one.

02:24.850 --> 02:26.410
So this one is one.

02:26.410 --> 02:28.650
So three minus one is just going to be two.

02:28.850 --> 02:33.570
And if we call this damage function for the second time max health is now two.

02:33.690 --> 02:35.650
So two minus one is going to be one.

02:35.650 --> 02:40.330
And if we call this takedamage function for the third time max health is now one.

02:40.330 --> 02:42.610
So one minus one is going to be zero.

02:42.610 --> 02:49.730
So our max health just going to hit zero whenever uh at some point it's hit it just going to hit zero.

02:50.010 --> 02:53.610
So in that moment we need to destroy our player game object.

02:53.610 --> 02:58.550
And let's, uh, let's suppose, uh, our max health is already zero.

02:58.550 --> 03:01.430
And let's suppose we call this function.

03:01.430 --> 03:03.150
So the max cell is zero.

03:03.150 --> 03:05.470
So zero minus one gonna be minus one.

03:05.470 --> 03:07.910
So it will move over to negative value.

03:07.910 --> 03:12.750
So before we subtract we want to check if the max cell is already zero.

03:12.790 --> 03:14.910
Then we need to stop subtracting.

03:14.910 --> 03:21.630
So we will check if if let's make first bracket and some curly brackets and what we want to check over

03:21.630 --> 03:21.870
here.

03:21.910 --> 03:28.310
We basically want to check if our max cell, if it's lesser than or equal to zero, means we need to

03:28.350 --> 03:28.750
stop.

03:28.750 --> 03:33.710
Subtracting means we need to stop executing this line of code which is subtracting.

03:33.710 --> 03:35.950
So that's why we're going to type this return.

03:35.950 --> 03:42.030
And after return, whatever we're going to do it's not going to be executed at all means our Maxwell

03:42.030 --> 03:43.630
just going to start at zero.

03:43.630 --> 03:50.430
As you can see, whenever our max cell hits zero, as you can see right over here, we type in return

03:50.430 --> 03:56.470
and after return, whatever we're going to do, it's not going to execute at all means our Maxwell just

03:56.470 --> 03:58.140
going to gonna start at zero.

03:58.900 --> 04:03.820
And we also need to create a die function in order to destroy our player.

04:03.980 --> 04:05.900
So let's make it over here.

04:05.900 --> 04:10.260
And this function doesn't need to be public or private or public.

04:10.260 --> 04:12.380
So we can make it private instead.

04:12.380 --> 04:19.940
So if we type void and if we don't assign a right in front of this, something like private or public,

04:19.980 --> 04:25.860
then this function automatically get marks as a mark marked as a private function.

04:26.300 --> 04:29.340
For function we type void and we have to name the function.

04:29.340 --> 04:30.540
So I'm going to call it die.

04:30.740 --> 04:33.260
Let's make first bracket and some curly brackets.

04:33.260 --> 04:39.980
So what we want to do inside this function we basically want to destroy our enemy one game object.

04:39.980 --> 04:45.940
But before we destroy let's print out the message that we want to see something like this enemy one

04:45.940 --> 04:47.140
game object dies.

04:47.140 --> 04:50.740
So for printing out message we're going to type this debug dot log.

04:51.060 --> 04:59.680
And we can say something like this dot game object dot name, dot name, and top of that I'm going to

04:59.680 --> 05:01.080
add a custom message.

05:01.080 --> 05:02.800
So use this plus icon.

05:02.800 --> 05:03.160
Sorry.

05:03.200 --> 05:09.200
Use this plus and then quotation and you can put whatever you want in between these quotation.

05:09.240 --> 05:13.640
Say something like diet and let's close that up with semicolon.

05:13.760 --> 05:17.640
So this dot game object basically means it just referencing itself.

05:17.640 --> 05:22.400
So the enemy one script we can see it's attached to this anime one game object.

05:22.400 --> 05:28.040
And we can see the name of this anime one in Inspector we can see is anime one.

05:28.040 --> 05:29.840
So the message should be pop up.

05:29.840 --> 05:34.560
So this right over here is just going to be anime one, basically the name of the game object.

05:34.560 --> 05:37.880
And on top of that we just added this message which says type.

05:37.920 --> 05:44.280
So anime one type message should be pop up in our console tab whenever we're going to call this function.

05:44.280 --> 05:51.680
So we can call this function once our Maxell loses zero right over here, we can call it uh, we can

05:51.680 --> 05:55.510
call it or we can call it in the update function as well.

05:55.510 --> 05:58.670
So let's call it inside update function instead of doing.

05:58.710 --> 05:59.230
There.

05:59.230 --> 06:01.630
So let's move over to this update function.

06:01.630 --> 06:03.670
So we do know that update function runs.

06:03.710 --> 06:05.070
Every single frame.

06:05.070 --> 06:08.550
So every single frame we're just going to keep track of our max cell.

06:08.710 --> 06:09.790
So we will check.

06:09.790 --> 06:13.070
If so let's make first bracket and some curly brackets.

06:13.070 --> 06:14.270
So what we want to check.

06:14.310 --> 06:18.630
Over here we basically want to check the max health of that animation.

06:18.630 --> 06:21.270
So if our max health max health.

06:21.310 --> 06:26.150
If it's less than or equal to zero means we need to destroy our plate.

06:26.270 --> 06:26.630
Sorry.

06:26.670 --> 06:28.550
We need to destroy our enemy.

06:29.150 --> 06:29.910
Itself.

06:29.910 --> 06:32.190
So we can simply call the die function.

06:32.190 --> 06:33.990
And what die function just going to do?

06:34.030 --> 06:34.390
It's going.

06:34.430 --> 06:40.470
To print out the message in the console says this dot game Objectname basically the name of the game

06:40.510 --> 06:42.510
object, which is anime one.

06:42.510 --> 06:45.350
And top of that we added this message says type.

06:45.390 --> 06:46.630
So enemy one died.

06:46.670 --> 06:49.550
Message should be pop up in our console tab.

06:49.550 --> 06:53.390
So let's call the function here once our max health reaches zero.

06:53.390 --> 06:54.970
So we're going to call the function ty.

06:55.170 --> 06:58.530
Let's make first bracket and then close that off with semicolon.

06:58.530 --> 07:01.290
And we're going to press down Ctrl s to save our script.

07:01.290 --> 07:03.170
And now let's move over to unity.

07:03.690 --> 07:12.290
So we should be able to notice that message whenever our Maxwell just reaches zero of this enemy one

07:12.290 --> 07:13.090
GameObject.

07:13.410 --> 07:19.050
But the thing is that we're not going to able to notice why we just made that Takedamage function,

07:19.050 --> 07:21.330
and we never calling it anywhere.

07:21.330 --> 07:22.930
So we also need to call it.

07:22.930 --> 07:29.890
But when we need to call it once, these are our player GameObject attack on this enemy one game object.

07:29.890 --> 07:34.090
Once our player GameObject attack on this enemy one GameObject.

07:34.090 --> 07:42.490
In that moment, we need to call that function from that enemy script or from that enemy one C class.

07:42.490 --> 07:44.610
So just wait a moment and you will see.

07:45.330 --> 07:55.030
And a nice title just gonna pop up underneath our enemy one script as says Max health or health as we

07:55.030 --> 07:56.350
have given the title.

07:56.630 --> 08:04.510
And also, I really apologize for taking a little bit longer time than as usual, you know that my system

08:04.510 --> 08:09.670
is a little bit slow, so that's why it's taking pretty much long time.

08:10.270 --> 08:18.230
Uh, so in this time lapse, I can just I can just explain what, uh, basically going on.

08:18.590 --> 08:25.510
And now enemy one script just getting compile, and once it's compiled, we can see underneath our enemy

08:25.550 --> 08:31.150
one script in Inspector Health pop up and the max health by default we have given five.

08:31.150 --> 08:36.990
So if I move over to my console tab and then click on this play button and try to damage this enemy,

08:36.990 --> 08:44.710
one game object, uh, this enemy, one game object, then this enemy one should lose, uh, some unit

08:44.750 --> 08:47.270
of health from this max health.

08:47.430 --> 08:49.550
But the problem is that it own.

08:49.590 --> 08:50.110
Why?

08:50.150 --> 08:53.260
Because we also need to call the Takedamage function.

08:53.260 --> 08:54.140
Let me show you.

08:55.060 --> 08:56.460
So just wait a moment.

08:57.620 --> 09:03.020
So now if we just get in attack range and try to attack on this enemy one.

09:03.420 --> 09:10.940
Uh, that, as you can see, uh, Max health is not going to four, three, two, one as even though

09:10.940 --> 09:14.100
we attacking, uh, even though we attacking.

09:14.100 --> 09:19.300
So what basically going on if I get out of play mode and then move over to my enemy.

09:19.340 --> 09:24.700
One script that we just created this function and we never calling it anywhere.

09:24.700 --> 09:31.340
So that's why this line of code not getting execute basically we not subtracting at all our damage amount.

09:31.340 --> 09:37.980
So when we need to do it, once our uh player GameObject attack on this enemy one game object.

09:37.980 --> 09:44.140
So if I move over to my console tab, as you can see, a message just getting pop up says circle colliding

09:44.140 --> 09:44.980
with enemy.

09:45.020 --> 09:50.500
Basically, if I select my player GameObject in the hierarchy, move over to animation tab and then

09:50.500 --> 09:52.440
choose this attack one or attack two.

09:52.480 --> 09:57.080
As you can see right over here, we created that attack function.

09:57.080 --> 10:00.600
So over here we can call the function which is damage amount.

10:00.600 --> 10:07.080
So basically what we need to do we need to open up our attack function inside this player game object

10:07.080 --> 10:08.840
that we created earlier.

10:09.120 --> 10:12.320
So we will select our player game object in the hierarchy.

10:12.360 --> 10:16.560
Then go over to Inspector and open up the player script by double clicking on it.

10:16.560 --> 10:18.800
And let's move over to that function.

10:18.800 --> 10:19.640
In which function?

10:19.640 --> 10:24.400
We just, uh, we basically, uh, just, uh, printing out the message.

10:24.400 --> 10:29.240
As you can see, if call info is true basically means the circle is colliding.

10:29.240 --> 10:32.960
Basically this circle colliding with this enemy one game object.

10:33.000 --> 10:36.920
Once our this player just playing the attack animation clip.

10:36.920 --> 10:43.240
So instead of printing out message like this, as you can see, uh, our circle collided with and the

10:43.240 --> 10:44.360
name of the game object.

10:44.360 --> 10:51.710
Instead of doing that, we can simply call the Takedamage function from that enemy class as we created

10:51.750 --> 10:54.710
before, so we can simply call it over here.

10:54.710 --> 10:57.230
So instead of printing out message, we're going to call.

10:57.230 --> 10:59.550
But before we call we just want to check.

10:59.710 --> 11:02.550
So what we want to check is the circle.

11:02.550 --> 11:08.990
If the circle is really collided with this enemy one game object, then only that moment we want to

11:09.230 --> 11:10.590
call the Takedamage function.

11:10.590 --> 11:15.150
Basically this enemy one just gonna take damage, else we're not gonna do it.

11:15.150 --> 11:18.910
So before we damage it, we need to check what we colliding with.

11:19.070 --> 11:24.190
So that's why we're going to use this call info in order to extract information.

11:24.190 --> 11:25.910
So we will use this if condition.

11:25.910 --> 11:28.710
Let's make first bracket and some curly brackets.

11:28.710 --> 11:30.390
So what we want to check over here.

11:30.390 --> 11:36.590
We basically want to check if call info dot game GameObject dot get component.

11:36.590 --> 11:39.390
And we will check for our enemy one script.

11:39.390 --> 11:44.030
So we will type enemy one if it's and then make this first bracket.

11:44.030 --> 11:48.390
And we will check if it's not equal to null basically means what.

11:48.430 --> 11:55.210
Basically this means call con, call info.com object basically means the game object the circle collided

11:55.210 --> 11:55.730
with.

11:55.730 --> 11:59.130
So the circle is just going to collide with this enemy one game object.

11:59.130 --> 12:02.050
Then what we're doing we just going over to that.

12:02.090 --> 12:04.570
Then we're just taking our enemy one script.

12:04.570 --> 12:08.210
As you can see Dot get component and enemy one.

12:08.210 --> 12:11.530
And we're checking if that script is not equal to null.

12:11.690 --> 12:17.770
So firstly we're just going over to this enemy one game object and accessing this enemy one script.

12:17.770 --> 12:23.690
And we're checking if this enemy one script is not equal to null basically means that this enemy one

12:23.770 --> 12:27.170
script is attached to this enemy, one game object.

12:27.170 --> 12:32.490
And indeed we can see enemy one script is attached to this enemy, one game object.

12:32.490 --> 12:38.690
So if that is the case and not equal to null, basically means that enemy one is script is attached

12:38.690 --> 12:40.490
to that enemy one game object.

12:40.530 --> 12:47.090
Now we can what we can do, we can simply call our Takedamage function from that enemy one script.

12:47.210 --> 12:50.590
But before we do, let's print out a message now.

12:51.790 --> 12:54.550
Say something like a text message.

12:54.550 --> 12:58.590
So we're going to type this debug dot log in order to print out message.

12:58.590 --> 13:02.630
And we can say any one taking damage something like that.

13:02.630 --> 13:06.430
And upon taking damage damage.

13:06.430 --> 13:08.350
And let's close that up with semicolon.

13:08.350 --> 13:11.390
And we're going to press down Ctrl S to save our script.

13:11.390 --> 13:13.270
And now let's move over to unity.

13:13.630 --> 13:17.830
And the circle really gonna collide with this enemy one.

13:17.830 --> 13:23.790
And we're checking if the enemy one script is not equal to null basically means that enemy one script

13:23.830 --> 13:26.310
attached to this enemy one game object.

13:26.310 --> 13:31.230
And indeed we can see enemy one script is attached to this enemy, one game object.

13:31.230 --> 13:37.670
Then what we're doing, we printing out a message in the console says enemy one taking damage.

13:37.950 --> 13:39.430
Enemy one taking damage.

13:39.430 --> 13:45.710
So this message is just going to pop up whenever we're gonna attack on this enemy one game object once

13:45.710 --> 13:50.540
our player just gonna attack on on to this enemy.

13:50.580 --> 13:51.460
One game object.

13:51.460 --> 13:53.220
So I'm going to select my console tab.

13:53.220 --> 13:57.380
And let's click on this play button in the top in order to play our game.

13:57.380 --> 13:59.140
And let's have a look on this.

13:59.140 --> 14:03.820
And we created the Takedamage function inside this enemy one script.

14:03.820 --> 14:05.820
So we need to call the function.

14:05.820 --> 14:10.660
So if we call that function then this enemy one just going to take damage.

14:10.660 --> 14:17.460
So if I get in attack range and then damage it basically uh attack on it, we can see a message.

14:17.460 --> 14:23.300
So if I pause my game in the top by clicking on this pause button in the top, you can see in the middle

14:23.340 --> 14:23.780
top.

14:24.020 --> 14:30.460
And if we move over to our console tab, we can see a message just getting pop up says enemy one taking

14:30.500 --> 14:31.140
damage.

14:31.140 --> 14:37.500
So instead of printing out message what we really want to do, we basically want to, uh, basically

14:37.500 --> 14:39.620
want to damage this enemy one.

14:39.620 --> 14:45.020
So let's get out of play mode and let's double click on this message in order to move over to that line

14:45.060 --> 14:45.700
of code.

14:45.700 --> 14:50.800
So instead of printing out message, we're going to call the Takedamage function from that enemy one

14:50.800 --> 14:51.200
script.

14:51.320 --> 14:56.080
So if I move over to enemy one script, as you can see we created the function.

14:56.080 --> 14:57.640
So we're going to call this function.

14:57.640 --> 15:01.040
So let's call it to call it what we're gonna do.

15:01.080 --> 15:08.680
We're going to use this call info parameter in order to access anything that we just are looking for.

15:08.680 --> 15:12.920
So we're going to access Call info dot GameObject and call info.

15:12.920 --> 15:19.200
Dot GameObject basically means the GameObject the circle collided with and we want to access the enemy

15:19.240 --> 15:19.840
one script.

15:19.840 --> 15:20.960
So let's get that.

15:20.960 --> 15:24.040
And to get that we're going to use this dot get component.

15:24.040 --> 15:28.480
And the component we're looking for is enemy one or enemy one script.

15:28.480 --> 15:30.600
You can simply say enemy one.

15:30.600 --> 15:32.160
Then make this first bracket.

15:32.160 --> 15:35.080
And in there we created that Takedamage function.

15:35.080 --> 15:38.720
So let's access that or let's simply call it here.

15:38.720 --> 15:43.280
So we're going to type this dot and we're going to call the Takedamage function.

15:43.280 --> 15:46.000
And then make this first bracket as a argument.

15:46.110 --> 15:51.630
It's going to take the damage amount as we pass the argument, as you saw earlier.

15:52.150 --> 15:59.870
So if you just put a three, then our enemy one just gonna die right away since we already given three

15:59.870 --> 16:00.990
unit of health.

16:01.030 --> 16:03.550
But I want to subtract by one unit.

16:03.550 --> 16:06.670
So that's why as a damage amount I'm going to pass one.

16:06.790 --> 16:08.950
And let's close that up with semicolon.

16:08.950 --> 16:15.470
So that enemy one game object just gonna lose one unit of health as soon as we're gonna attack on it.

16:15.670 --> 16:20.470
And now we're gonna press down Ctrl s to save our script and then move over to unity.

16:20.550 --> 16:25.750
So as soon as we're gonna damage this enemy one, we will able to notice this.

16:25.750 --> 16:27.950
Maxhealth just gonna move over to.

16:27.990 --> 16:28.470
Sorry.

16:29.030 --> 16:31.030
Uh, we have given three.

16:32.990 --> 16:33.790
It shouldn't be.

16:33.830 --> 16:35.110
It should be five.

16:35.230 --> 16:36.110
Uh, I don't know.

16:36.310 --> 16:40.990
We have given, uh uh, three, but I don't know.

16:42.150 --> 16:49.090
I really apologize that we have given five Instead of giving five, I'm gonna pass three as a maxhealth.

16:49.450 --> 16:52.650
Uh, so I'm gonna pass three right over here.

16:52.690 --> 16:53.730
Now, this is fine.

16:54.290 --> 16:56.530
So this seems pretty much cool by now.

16:56.530 --> 17:02.530
So if we attack on this enemy one game object three times, then it's gonna lose all of his health.

17:02.530 --> 17:08.370
And once it's lose all of his health, then what we're doing, if we move over to enemy one script we

17:08.730 --> 17:10.450
call calling the die function.

17:10.450 --> 17:16.930
As you can see, once our maxhealth is less than or equal to zero, then we calling the die function

17:16.930 --> 17:18.170
and die function.

17:18.170 --> 17:22.730
Simply printing out this message in the console says enemy one died.

17:22.770 --> 17:23.810
As you can see.

17:23.970 --> 17:27.490
So now let's move over to unity and let's select the console tab.

17:27.650 --> 17:31.970
And let's click on this play button in the top in order to play our game.

17:31.970 --> 17:35.330
And let's attack on this enemy one game object.

17:35.330 --> 17:41.530
So, uh, once we are gonna attack three times, it's gonna lose all of his health, then die function.

17:41.530 --> 17:43.770
Just gonna call out and die function.

17:43.770 --> 17:46.840
Just going to print out the message says enemy one died.

17:46.880 --> 17:48.320
So let's attack on it.

17:48.320 --> 17:52.040
So if I attack so maxhealth we can see it's now became two.

17:52.080 --> 17:55.800
If we attack second time, we can see it's now one.

17:55.800 --> 17:58.600
And if we attack third time, then it's going to be zero.

17:58.720 --> 18:00.920
And we can see max health is zero.

18:00.920 --> 18:06.480
And as soon as it reaches zero, if we move over to console tab, enemy one died.

18:06.520 --> 18:09.240
Message just getting pop up every single time.

18:09.240 --> 18:09.600
Why?

18:09.800 --> 18:12.800
Because we're calling inside this update function.

18:12.800 --> 18:15.920
And we do know that update function runs every single frame.

18:15.920 --> 18:17.240
So every single frame it.

18:17.240 --> 18:21.000
Just checking the max if is then just calling that I function.

18:21.000 --> 18:26.680
So that's why every single frame the die function is calling out, and the die function simply printing

18:26.680 --> 18:29.440
out this passage over again and again.

18:29.440 --> 18:32.920
So we need to show up a die, something like that.

18:32.960 --> 18:34.480
We need to show that up.

18:34.800 --> 18:39.560
So death animation we need to play up this enemy one game object.

18:39.560 --> 18:41.200
So I'm going to get out of play mode.

18:41.200 --> 18:44.120
So I hope you get the idea that how you can do it.
