WEBVTT

00:00.040 --> 00:06.120
When we are getting closer to our player game object, we simply printing out a message in our console

00:06.120 --> 00:09.240
tab saying as saying enemy to attack.

00:09.240 --> 00:16.320
So basically, if I move over to my enemy two script, we simply play printing out this message say

00:16.360 --> 00:23.360
play, play, enemy to attack, animation play enemy to attack animation.

00:23.360 --> 00:30.560
So instead of printing out message a play enemy to attack animation instead of printing out message

00:30.560 --> 00:35.880
what we really want to do, we basically want to play the attack animation clip of this enemy two game

00:35.920 --> 00:36.440
object.

00:36.480 --> 00:42.320
Basically, if we select our enemy two GameObject in the hierarchy, then move over to animator tab.

00:42.320 --> 00:44.600
So we need to trigger this attack parameter.

00:44.600 --> 00:47.840
We do know that if we uh sorry, not gonna trigger.

00:47.840 --> 00:51.160
Basically we need to set this attack parameter to true.

00:51.160 --> 00:57.880
So in that lecture animation transition lecture we have done it inside this enemy two game object.

00:58.120 --> 01:00.440
So if you didn't watch that lecture.

01:00.440 --> 01:02.720
So make sure you watch that lecture.

01:02.760 --> 01:07.400
Then, uh, then you can just, uh, come into this lecture.

01:07.680 --> 01:10.240
So we need to set this attack parameter to true.

01:10.240 --> 01:15.120
But before we set what we need, we need a reference of this animator component.

01:15.120 --> 01:16.640
Then we can just do that.

01:16.640 --> 01:18.880
So let's grab the components.

01:18.880 --> 01:22.440
And also we're gonna set this attack parameter to true.

01:22.440 --> 01:23.560
So let's do that.

01:23.560 --> 01:27.080
So we're going to open up our animator script by double clicking on it.

01:27.800 --> 01:30.040
And let's go to top of our class.

01:30.040 --> 01:31.960
And let's make it over here.

01:31.960 --> 01:34.040
So that parameter doesn't need to be public.

01:34.040 --> 01:36.320
So we can make it private instead.

01:36.320 --> 01:39.320
And the component we're looking for is animator.

01:39.320 --> 01:41.160
So we're going to type this animator.

01:41.160 --> 01:44.880
And we have to name the uh we have to name the parameter.

01:44.880 --> 01:52.840
So I'm going to call it something like animator with small letter with a with a non non capitalized

01:52.880 --> 01:54.800
a letter as you can see.

01:55.040 --> 01:57.240
Now let's move over to this start function.

01:57.240 --> 01:59.970
So in this start of the game we're going to grab that.

01:59.970 --> 02:06.250
So we will use this this start this start game object dot get component.

02:06.250 --> 02:07.690
And let's make this arrow.

02:07.850 --> 02:11.370
So we're going to pass inside this arrow which is animator.

02:11.370 --> 02:15.250
And then make this first bracket and then close that up with semicolon.

02:15.290 --> 02:20.250
Now so we just simply getting the component which is animator that we're looking for.

02:20.250 --> 02:22.770
Now we have the component as you can see.

02:22.810 --> 02:27.770
Now let's store this animator component into this animator variable.

02:27.770 --> 02:32.170
So store that animator component into this animator variable.

02:32.170 --> 02:37.250
So let's set a animator equal to this dot game object dot get component.

02:37.610 --> 02:40.970
So this dot game object basically is just referring itself.

02:40.970 --> 02:43.370
And we're just getting this animator component.

02:43.370 --> 02:48.330
And after getting it we're storing this animator component into this animator variable.

02:48.330 --> 02:56.050
As you can see right over here we are saying animator equal to this dot game object dot get component

02:56.050 --> 02:56.850
animator.

02:56.850 --> 03:00.810
Now we have the reference by now and we are ready to set that.

03:00.810 --> 03:03.730
So we need to set our attack parameter to true.

03:03.890 --> 03:08.410
To do that, we will move over to this line of code over here, as you can see.

03:09.010 --> 03:17.570
So also we are printing out this message in our console tab says like anime play anime to attack animation.

03:17.570 --> 03:22.410
So instead of printing out message we need to set that attack parameter to true.

03:22.410 --> 03:28.490
So we will go to animator component and we're going to use this set bool function because that parameter

03:28.490 --> 03:29.130
is a bool.

03:29.130 --> 03:32.010
So that's why we need to use this set bool function.

03:32.010 --> 03:34.170
And then make this first bracket.

03:34.370 --> 03:40.530
And inside this quotation as a first argument it's going to take the parameter name which is attack,

03:40.530 --> 03:42.450
and make sure you spelling it correct.

03:42.450 --> 03:45.050
And the second thing comma it's going to take the value.

03:45.050 --> 03:47.410
So we're going to set it to true basically means take.

03:47.410 --> 03:50.090
And we do know if we check or set it to true.

03:50.130 --> 03:54.530
It's going to play the attack animation clip of that anime two game object.

03:54.530 --> 03:56.890
And now we're going to close that up with semicolon.

03:57.050 --> 03:59.860
And let's press down Ctrl S to save our script.

03:59.900 --> 04:01.660
And now let's move over to unity.

04:01.780 --> 04:08.260
So as soon as we're gonna get closer to our player game object, and this enemy to game object will

04:08.260 --> 04:12.900
get closer to this player game object and this enemy to game object.

04:12.900 --> 04:19.180
Just gonna play the attack animation clip once it's get too much closer to this player game object.

04:19.380 --> 04:20.900
So just wait a moment.

04:21.060 --> 04:27.300
Once the compilation is done, we can just go ahead and we can play our game in order to check that

04:27.300 --> 04:27.860
out.

04:28.020 --> 04:29.340
So just wait a moment.

04:31.300 --> 04:37.260
So once it's done, we can just go ahead and we can just play our game in order to check that out.

04:37.700 --> 04:40.540
So now wait for a little moment.

04:43.740 --> 04:50.300
So we simply instead of printing out message by now, we simply just setting that attack parameter to

04:50.340 --> 04:50.660
true.

04:50.700 --> 04:53.180
As you can notice any animator tab.

04:53.180 --> 04:57.820
And we do know that if we just check that or set it to true.

04:57.860 --> 05:01.940
This anime to game object just gonna play the attack to animation clip.

05:01.940 --> 05:05.740
So let's click on this play button in the top in order to play our game.

05:05.740 --> 05:07.260
Let's take a look on it.

05:12.820 --> 05:14.220
So just wait a moment.

05:17.540 --> 05:20.220
So now let's get with chasing.

05:20.460 --> 05:29.100
And as soon as we get closer as you can notice that this anime two game object just playing the attack

05:29.460 --> 05:33.700
animation clip over again and again, again and again.

05:33.740 --> 05:41.100
But if we just get outside of this attack range, we can still able to notice that this enemy two just,

05:41.140 --> 05:46.420
uh, playing the attack animation clip over again and again and it's playing forever.

05:46.420 --> 05:52.020
It's not going back to our work animation clip to go back and work animation clip.

05:52.060 --> 05:55.820
We do know that we need to set this attack parameter to false.

05:55.820 --> 06:01.190
And we do know that once we're gonna set it, it's going to play the play the work animation clip.

06:01.190 --> 06:04.710
So let's get out of play mode and let's set it through our code.

06:04.710 --> 06:06.630
So let's move over to our scape.

06:06.630 --> 06:07.510
And over here.

06:07.510 --> 06:11.670
As you can see we chasing our player game object right over here.

06:11.670 --> 06:17.390
So when we are chasing we need to play the play the work animation clip instead of attack.

06:17.390 --> 06:19.790
So that's why we're going to copy this line of code.

06:19.830 --> 06:25.590
Basically we will go over to animator animator and we're going to use this set bool function.

06:25.590 --> 06:30.910
And as a second second argument we're gonna set it to false or basically means unchecked.

06:30.910 --> 06:36.950
And we do know once we're gonna uncheck or we're gonna set it to false, it will play the, uh, it

06:36.950 --> 06:40.590
will play the work animation clip instead of the attack one.

06:40.870 --> 06:44.670
Uh, so let's, uh, pass our value, which will be false.

06:44.670 --> 06:47.670
And now we're going to press down Ctrl s to save our script.

06:47.670 --> 06:49.590
And now let's move over to unity.

06:49.830 --> 06:55.830
So as soon as we're gonna get out of attack range or from this enemy to game object, you will see this

06:55.830 --> 06:56.910
anime two game object.

06:56.910 --> 07:02.470
Just gonna play the work animation clip right away instead of playing the anime to attack animation

07:02.470 --> 07:03.030
clip.

07:03.030 --> 07:07.430
So just wait a little moment and once it's done, we can just check that out.

07:07.430 --> 07:15.190
So now if I just, uh, go ahead and click on this play button in the top in order to play our game.

07:15.230 --> 07:17.030
Let's take a look on this.

07:18.270 --> 07:19.670
So just wait a moment.

07:19.990 --> 07:26.790
So whenever we're gonna get outside of that attack range, this anime two game object just gonna play

07:26.790 --> 07:27.470
the attack.

07:27.750 --> 07:28.910
Uh, sorry.

07:28.950 --> 07:30.070
Work animation clip.

07:30.070 --> 07:32.510
As you can see, indeed it's playing.

07:32.710 --> 07:39.190
And when we go to the right side, we can see it's now playing the animation clip as well.

07:39.190 --> 07:46.070
But the problem is that I want this anime two game object to stop a little bit further away from this

07:46.070 --> 07:52.910
player game object, because we can see that this, uh, this, uh, basically the weapon just getting

07:52.910 --> 07:56.350
outside of the player or overlapping with the player.

07:56.470 --> 07:58.590
I want to be something over here.

07:58.590 --> 08:04.150
So that's why we need to stop our, uh, enemy two game object a little bit further away.

08:04.190 --> 08:10.470
Basically, we need to just bump up the retrieve distance between this player and this enemy to game

08:10.510 --> 08:11.070
object.

08:11.070 --> 08:16.110
So let's get out of play mode and we will select our enemy two GameObject in the hierarchy.

08:16.310 --> 08:22.630
Let's go over to enemy two Script in Inspector, and we're going to increase the retrieve distance.

08:22.630 --> 08:27.390
So let's set it set the retrieve distance to something like 4.5.

08:27.910 --> 08:29.710
And let's click on this play button.

08:29.950 --> 08:32.910
And we can check that out in play mode as well.

08:32.910 --> 08:38.590
And once we get out of play mode we can just remember the number and we can put it back.

08:38.590 --> 08:42.070
So just wait a moment and we can check that out.

08:42.390 --> 08:44.310
So now it should work fine.

08:44.310 --> 08:50.150
If it's not we can just do it in, uh, do it in this enemy two.

08:50.310 --> 08:53.230
As you can see, this seems pretty much cool by now.

08:53.560 --> 08:59.480
uh, if you want a little bit further away, then you can just increase the retrieve distance so we

08:59.480 --> 09:04.600
can do something like 4.6, I guess 4.6.

09:04.640 --> 09:07.040
Sorry, 4.6.

09:07.040 --> 09:09.480
Now we can see it's pretty much fine.

09:09.480 --> 09:12.000
So 4.6 seems a perfect number.

09:12.000 --> 09:13.720
So let's get out of play mode.

09:13.720 --> 09:19.120
And let's put the number back to back from this 4.5 to 4.6.

09:19.320 --> 09:23.600
Because if you do any changes in play mode it's not gonna save at all.

09:23.600 --> 09:25.840
So make sure you just remember the number.

09:25.840 --> 09:28.160
Or you can simply right click on the component.

09:28.160 --> 09:30.520
Then click on the scope copy component.

09:30.520 --> 09:37.160
And when you get out of play mode, then right click on it and then paste the component value, uh value

09:37.200 --> 09:39.400
by right clicking you're gonna get that.

09:39.400 --> 09:41.160
So I hope you get the idea.

09:41.160 --> 09:46.920
And now what we need to do, we need to give some health amount to this enemy to game object in order

09:46.920 --> 09:48.040
to take damage.

09:48.040 --> 09:53.320
And when we're gonna take damage, then this enemy two game object need to play the heart animation

09:53.320 --> 09:53.800
clip.

09:53.920 --> 09:55.800
So we need to before we damage it.

09:55.840 --> 10:00.720
We basically need to give some health amount to this enemy to game object.

10:00.880 --> 10:04.240
So let's open up the enemy two script by double clicking on it.

10:04.240 --> 10:06.440
And let's go to the top of our class.

10:06.840 --> 10:10.640
And over here, uh, let's give it a title first.

10:10.640 --> 10:13.280
So we're going to make this header header.

10:13.280 --> 10:15.960
And let's call this something like health.

10:16.080 --> 10:18.040
So let's call it hell.

10:19.080 --> 10:20.240
Uh, hell something.

10:20.280 --> 10:22.200
Sorry I misspell it.

10:22.240 --> 10:22.760
Hell.

10:22.960 --> 10:24.320
And now this is fine.

10:24.640 --> 10:26.800
So let's make a serialized field.

10:27.200 --> 10:31.400
So let's make a serialized field, uh, private.

10:31.400 --> 10:35.200
And that will be int, like, whole numbers zero, one, two, three, four.

10:35.400 --> 10:38.840
And we can call this one something like Max health.

10:38.960 --> 10:42.840
And by default I'm gonna give something around three unit of health.

10:43.080 --> 10:46.480
And now let's make a function in order to take damage.

10:46.560 --> 10:51.640
So we're going to scroll down to the bottom and let's make it somewhere over here.

10:51.640 --> 10:53.450
It doesn't need to be in order.

10:53.450 --> 10:56.570
You can just make it anywhere you would like to go with.

10:56.610 --> 10:57.890
You can just do it.

10:57.890 --> 11:03.330
So we will make this function public, because we're going to call this function from another class

11:03.330 --> 11:04.810
or another script.

11:04.810 --> 11:07.730
That's why we're gonna make this function.

11:07.970 --> 11:10.450
Or we're gonna mark this function as public.

11:10.690 --> 11:14.690
So for public and for function we're gonna type void.

11:14.690 --> 11:16.530
And we have to name the function.

11:16.530 --> 11:20.290
So I'm going to call it something like take damage take damage.

11:20.290 --> 11:23.330
And let's make first bracket and some curly brackets.

11:23.330 --> 11:26.050
So this take damage in arguments.

11:26.090 --> 11:29.490
It's going to take an argument which will be a damage amount.

11:29.490 --> 11:30.370
So let's pass.

11:30.370 --> 11:34.210
And that will be int like int type like 01234.

11:34.330 --> 11:36.930
And we can call this one damage amount.

11:36.970 --> 11:41.250
Basically we're doing the same thing as we have done inside our player skip.

11:41.250 --> 11:46.210
So if I move over to my player skip we already created a take damage function.

11:46.210 --> 11:52.290
I guess if it's not sorry we have done inside this enemy to animated game object.

11:52.530 --> 11:54.570
Sorry anime one I really apologize.

11:54.610 --> 11:57.970
Anime one as you can notice right over here.

11:57.970 --> 11:59.650
So we're gonna do the same thing.

11:59.650 --> 12:06.210
So you can simply copy this line of code by Ctrl C and you can just paste inside your anime script,

12:06.210 --> 12:10.490
but I'm gonna do it from scratch to explain it better.

12:10.490 --> 12:12.210
So damage amount.

12:12.210 --> 12:17.450
So before we damage, we need to check the health of our anime to game object.

12:17.450 --> 12:18.730
It's already zero.

12:18.770 --> 12:21.170
Then we don't need to damage it.

12:21.330 --> 12:22.850
Damage after that.

12:23.130 --> 12:25.650
After that we don't want to damage.

12:25.650 --> 12:27.970
So before we damage, we just want to check.

12:28.130 --> 12:33.210
If so, let's make first bracket and some curly brackets and what we want to check over here.

12:33.210 --> 12:39.130
We basically want to check if our maxhealth of this anime two game object, if it's less than or equal

12:39.130 --> 12:39.810
to zero.

12:39.970 --> 12:46.330
If that is the case, then we don't want to damage at all, damage or damage at all.

12:46.330 --> 12:54.660
But if the max is not less than or equal to zero, basically means that enemy two game object is still

12:55.100 --> 12:58.260
have some health amount, so else condition else.

12:58.260 --> 13:03.300
If the enemy to game object have some health amount, then we're gonna damage it.

13:03.300 --> 13:08.380
So that's why from this maxhealth we're going to subtract minus equal our damage amount.

13:08.380 --> 13:12.900
And later on we're gonna replace this damage amount with something like one.

13:13.220 --> 13:17.500
And if the max health reaches zero then we need to stop subtracting.

13:17.500 --> 13:19.620
So that's why we're going to type this return.

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

13:26.260 --> 13:30.060
So the max health we subtracting damage amount as you can see.

13:30.980 --> 13:35.980
So let's suppose we call this Takedamage function for the first time for the first time.

13:35.980 --> 13:38.260
So maxhealth by default we have given three.

13:38.300 --> 13:43.260
If I scroll up, as you can notice maxhealth I already given three.

13:43.260 --> 13:47.540
So this one right over here, the max health just gonna be three.

13:48.140 --> 13:51.260
So the max health is not less lesser than or equal to zero.

13:51.260 --> 13:54.340
So it's going to jump over to this else condition.

13:54.340 --> 13:59.100
And what we're doing inside this else condition we just subtracting our damage amount.

13:59.100 --> 14:02.620
And let's assume as a damage amount we just pass one.

14:02.620 --> 14:04.100
So the max is three.

14:04.340 --> 14:06.340
And this damage amount is one.

14:06.340 --> 14:11.580
And if we call this takedamage function so the Maxwell is three and the damage amount is one.

14:11.580 --> 14:13.340
So three minus one two.

14:13.540 --> 14:16.700
And if we call this takedamage function for the next time.

14:16.700 --> 14:18.300
So the max health is now two.

14:18.340 --> 14:23.020
So two minus one is going to be one uh two minus one gonna be one.

14:23.020 --> 14:25.980
And if we call this take damage for the third time.

14:25.980 --> 14:28.620
So the Maxwell is now one one.

14:28.620 --> 14:31.100
And this damage amount we assume it one.

14:31.100 --> 14:33.220
So one minus one gonna be zero.

14:33.220 --> 14:38.020
So somehow our max health of this enemy two game object just gonna reaches zero.

14:38.180 --> 14:44.660
And once it reaches zero, as you can see, if Maxwell is less than or equal to zero, then we typing

14:44.660 --> 14:45.220
return.

14:45.260 --> 14:51.190
Return basically means after return, whatever we're gonna do, it's not gonna be executed at all.

14:51.230 --> 14:52.950
Basically means our max health.

14:53.070 --> 14:56.790
So this line of code will not be call out means our max.

14:56.790 --> 14:58.830
Hell, just gonna start at zero.

14:59.390 --> 15:02.270
So Max health just loses all of his health.

15:02.350 --> 15:03.990
So now what we have to do?

15:04.030 --> 15:07.870
We're gonna make a die function in order to print out the message.

15:08.550 --> 15:10.270
So let's make a die function.

15:10.270 --> 15:12.070
So I'm going to make it over here.

15:12.310 --> 15:18.750
And you can assume that basically we're doing the same thing as we have done inside that enemy one script.

15:18.790 --> 15:22.790
We're doing the same thing or we just approaching in the same way.

15:23.230 --> 15:25.230
So for function we're going to type void.

15:25.230 --> 15:28.150
And this function doesn't need to be public or private.

15:28.150 --> 15:35.110
So this function just gonna automatically marked as a private function if we don't assign a don't assign

15:35.150 --> 15:38.590
in front of this void, something like private or public.

15:38.590 --> 15:42.430
So this function automatically just gonna marked as a private function.

15:42.710 --> 15:44.270
And we have to name the function.

15:44.270 --> 15:45.510
So I'm going to call it die.

15:45.550 --> 15:49.070
Let's make first bracket and some curly brackets for function.

15:49.230 --> 15:52.910
For now, we're going to print out a message something like this.

15:52.950 --> 15:58.510
Anime two game object dice for printing out message I'm going to type this Debug.log and we're going

15:58.510 --> 16:02.470
to say this dot game object dot name.

16:02.750 --> 16:05.870
And top of that I'm going to add a message custom message.

16:05.870 --> 16:09.150
So you need to use this plus icon and this quotation.

16:09.150 --> 16:12.870
And you can just add up the custom message that you want.

16:12.910 --> 16:15.870
So I'm going to say something like diet diet.

16:15.870 --> 16:17.990
And let's close that up with semicolon.

16:17.990 --> 16:23.070
So this dot game object dot name basically means the game object referencing itself.

16:23.070 --> 16:25.110
And the way we accessing the name.

16:25.110 --> 16:30.830
So this enemy two script is attached to this anime two game object, as you can notice in the inspector.

16:30.830 --> 16:32.430
So we accessing the name.

16:32.430 --> 16:34.790
So the name we can see is anime two.

16:34.830 --> 16:37.830
So right over here the name just going to be anime two.

16:37.830 --> 16:40.870
And top of that we just added this message says type.

16:40.950 --> 16:46.670
So anime two enemy two diet message should be pop up in our console tab.

16:46.870 --> 16:49.150
So we also need to call this function.

16:49.150 --> 16:53.310
Once our maxalt of that enemy two game object reaches zero.

16:53.510 --> 16:59.350
And over here, as you can notice, we're checking if the max cell is already less than or equal to

16:59.390 --> 17:05.310
zero means our enemy two game object just loses all of his health and all of his health.

17:05.350 --> 17:07.550
The max health is now zero.

17:07.550 --> 17:13.670
So we are we are ready to call the die function here, because enemy two game object just loses all

17:13.670 --> 17:14.430
of his health.

17:14.430 --> 17:18.790
So we're gonna call the die function here, and let's make first bucket and then close that up with

17:18.790 --> 17:19.710
semicolon.

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

17:22.550 --> 17:24.230
And let's move over to unity.

17:24.470 --> 17:32.270
So as soon as we're gonna start taking damage from our player game object this enemy to enemy to health

17:32.270 --> 17:34.030
just gonna reach zero.

17:35.070 --> 17:39.110
But the problem is that we're not gonna take any damage at all.

17:39.110 --> 17:39.510
Why?

17:39.870 --> 17:45.590
Uh, because we just made the Takedamage function, and we just never calling it anywhere.

17:45.590 --> 17:47.480
So we also need to call that function.

17:47.480 --> 17:49.480
But before we call, let me show you.

17:49.480 --> 17:56.920
So the max cell, as you can see underneath our enemy two script is held as we just given as a default

17:56.920 --> 17:57.480
value.

17:57.480 --> 17:58.920
So the Maxwell is three.

17:59.040 --> 18:04.520
And if we just go ahead and then click on this play button in the top, you will see this enemy two

18:04.560 --> 18:05.080
game object.

18:05.120 --> 18:07.520
Not gonna lose any of his health.

18:07.520 --> 18:07.920
Why?

18:08.000 --> 18:12.280
Because we that made the function take damage and we never calling it.

18:12.280 --> 18:14.000
So we also need to call.

18:14.000 --> 18:17.120
So let's take damage from this our player game object.

18:17.120 --> 18:22.360
You will see uh so if I damage my player enemy two game object.

18:23.120 --> 18:30.960
As you can see, the max health underneath our enemy two script is stuck at zero and it's not going

18:31.000 --> 18:31.560
down.

18:31.560 --> 18:37.120
So we we do know that we just made that function, which is take damage and we never calling it.

18:37.120 --> 18:38.120
So we need to call it.

18:38.120 --> 18:44.680
So let's get out of play mode where we need to call it once this plays attack animation clip basically

18:44.720 --> 18:51.840
once our player GameObject plays attack animation and the circle just collides with this enemy two GameObject.

18:51.880 --> 18:53.760
At that moment we're going to call it.

18:53.760 --> 18:56.000
So if I open up my enemy two script.

18:56.520 --> 19:01.400
So as you can notice right over here, we just made the function and we never calling it.

19:01.400 --> 19:07.360
So that's why this line of code not getting executed, basically we're not taking any damage at all.

19:07.360 --> 19:10.120
So we also need to call this Takedamage function.

19:10.120 --> 19:16.600
But when we need to call it once our player GameObject, this player game object is attack on this enemy

19:16.640 --> 19:17.680
to game object.

19:17.680 --> 19:20.840
So let's open up the player script where we attacking.

19:20.840 --> 19:23.840
So we will select our player GameObject in the hierarchy.

19:23.960 --> 19:27.840
And let's open up the player script by double clicking on it in the Inspector.

19:28.040 --> 19:31.120
And let's go to attack function where we attacking.

19:31.280 --> 19:35.520
So right over here, as you can see we attacking right here.

19:35.840 --> 19:38.520
So we firstly just checking.

19:38.520 --> 19:44.880
So as you can see we damaging our enemy one game object once the circle collided with that enemy one

19:44.930 --> 19:45.770
game object.

19:45.770 --> 19:49.050
So we're gonna do the same thing over here as well.

19:49.610 --> 19:56.610
But before we do, make sure you assign your anime to game object as a anime layer because we just damaging

19:56.610 --> 19:58.930
our anime layer, so that's why.

19:58.970 --> 20:04.970
So if I select my anime to game object in the hierarchy and then go over to Inspector, we can see the

20:04.970 --> 20:11.930
tag, we assign it anime, and also we assign it this anime to game object as a anime layer.

20:11.930 --> 20:17.490
So now it's basically this anime two game object is ready to take damage.

20:17.490 --> 20:19.490
So now we need to call the function.

20:19.490 --> 20:24.250
So before we call the function we need to check if the circle is really collided.

20:24.250 --> 20:28.770
So if I select my player game object, as you can see we created this circle.

20:28.770 --> 20:35.690
And if that circle really collide with this anime game object, then we only then at that moment we're

20:35.690 --> 20:40.730
gonna call the Takedamage function, else we're not gonna do it or at all.

20:40.730 --> 20:46.290
So before we damage our enemy to game object, we need to check if this circle really collided with

20:46.290 --> 20:47.330
this enemy to game.

20:47.370 --> 20:48.330
Object or not.

20:48.370 --> 20:53.050
If it's then this enemy two game object need to take damage as it shouldn't.

20:53.050 --> 20:54.170
So that is the thing.

20:54.170 --> 20:59.370
So that's why before we damage we gonna check so we can just use this else if.

20:59.370 --> 21:02.530
Or you can just make this if condition as well.

21:02.530 --> 21:05.490
And then make the first bracket and some curly brackets.

21:05.490 --> 21:07.770
And you can put else if as well.

21:07.770 --> 21:08.610
So let's do it.

21:08.650 --> 21:14.570
Else if sorry we're gonna do that else if else if.

21:14.770 --> 21:18.890
And we need to pass the condition over here in brackets.

21:18.890 --> 21:20.090
So what we want to check.

21:20.090 --> 21:22.090
We basically want to check the game.

21:22.490 --> 21:24.370
The game object that we damaging.

21:24.370 --> 21:28.690
If that game object has a script called enemy two script or not.

21:28.690 --> 21:34.130
So we're going to type this call info dot game object dot get component.

21:34.130 --> 21:36.930
And the component we're looking for is enemy two.

21:37.050 --> 21:40.050
Since we want to damage our enemy two game object.

21:40.050 --> 21:42.930
So that's why we need to access the enemy two script.

21:43.130 --> 21:47.100
So we're going to pass our anime to and then make this first bucket.

21:47.100 --> 21:50.860
And we will check if the script is not equal to null.

21:50.900 --> 21:58.300
Basically means this script, this anime to script is attached to our anime, this anime game object.

21:58.300 --> 22:01.740
Firstly what we're doing, we're just going over to that game object.

22:01.740 --> 22:07.100
So call info dot GameObject basically means the game object the circle collided with as.

22:07.300 --> 22:10.620
So the circle is just going to collide with this enemy to game object.

22:10.660 --> 22:13.540
Then what we're doing, we're just getting the anime to script.

22:13.820 --> 22:16.620
So we're just going over to this anime to script.

22:16.620 --> 22:19.900
So firstly we're just going over to this anime to game object.

22:19.900 --> 22:25.180
And we accessing this anime script and we checking if it's not equal to null.

22:25.220 --> 22:31.580
It's basically means that this anime script is this anime two script is attached to this anime two game

22:31.620 --> 22:32.220
object.

22:32.220 --> 22:37.660
And indeed we can notice this anime two script is attached to this anime two game object.

22:37.660 --> 22:40.020
So now we are ready to damage.

22:40.020 --> 22:44.340
So we need to call the Takedamage function from that animated script by now.

22:44.500 --> 22:44.900
So?

22:45.100 --> 22:47.940
So that's why we check before we damage.

22:47.940 --> 22:54.180
So we just checking if the enemy two script is attached to that enemy two game object or not.

22:54.660 --> 22:56.780
So now we are ready to damage.

22:56.780 --> 23:02.700
So to damage that we will go to call info dot GameObject basically means we just going over to that

23:02.700 --> 23:04.780
enemy, uh to GameObject.

23:04.780 --> 23:08.980
And now we're gonna use this dot get component and make these errors.

23:08.980 --> 23:13.180
And inside these errors you need to pass the component that you are looking for.

23:13.180 --> 23:18.020
So we're looking for enemy to script component or enemy to subclass.

23:18.020 --> 23:23.620
So that's why we're going to pass this enemy to enemy to see script then make this first bracket.

23:23.740 --> 23:29.100
And now we need to call the function that we created inside that enemy two function.

23:29.380 --> 23:30.860
Uh sorry enemy two script.

23:30.860 --> 23:32.220
So the function dot.

23:32.260 --> 23:35.940
So we're going to type this dot and let's call the Takedamage function.

23:35.940 --> 23:39.580
And let's make first bracket and then close that up with semicolon.

23:39.580 --> 23:41.980
And as you can notice this take damage.

23:42.140 --> 23:45.660
It's gonna take, uh, the argument, which is damage amount.

23:45.660 --> 23:49.780
So if you just pass three right over here, then enemy just gonna.

23:49.860 --> 23:50.860
Enemy two, game object.

23:50.860 --> 23:53.620
Just gonna lose all of his health right away.

23:53.900 --> 23:55.380
And I don't want that.

23:55.380 --> 24:02.340
Because since we have given to this enemy two game object the Maxwell, as you can notice right over

24:02.340 --> 24:02.620
here.

24:02.620 --> 24:03.220
Three.

24:03.220 --> 24:07.220
So I don't want to destroy my enemy to game object right away.

24:07.220 --> 24:12.020
So that's why as a damage parameter or damage amount I'm gonna pass one.

24:12.060 --> 24:15.020
I just want to subtract by one unit.

24:15.020 --> 24:15.940
So that's why.

24:16.260 --> 24:22.660
And now if we press down Ctrl s to save our skip and then move over to unity editor, it's gonna be

24:23.100 --> 24:24.380
it's gonna work fine.

24:24.380 --> 24:29.540
So firstly, what we're doing, we're just going over to this enemy two script, as you can see.

24:29.660 --> 24:34.900
And inside this enemy two script, we can notice that we just made this Takedamage function.

24:34.900 --> 24:41.020
So we're just calling this function there once our player just attacking on enemy two game object.

24:41.070 --> 24:43.390
As you can notice right over here.

24:43.390 --> 24:49.110
Firstly we're just going getting the enemy to script and then we're just calling the function from there.

24:49.230 --> 24:50.590
And now it's gonna work fine.

24:50.590 --> 24:55.630
So let's move over to our unity editor and let's check that out.

24:56.310 --> 24:58.230
So I'm going to click on this play button.

24:58.230 --> 25:02.830
And by now you will be able to notice this enemy two game object.

25:02.830 --> 25:05.390
Just gonna able to take damage.

25:05.390 --> 25:08.070
So just wait a moment and you will see that.

25:08.310 --> 25:10.830
So the max health by default we have given three.

25:11.710 --> 25:17.030
So let's get closer to this enemy two game object and let's damage it.

25:17.030 --> 25:19.190
Now we can see the max health is two.

25:19.230 --> 25:22.910
And if we damage one more time the max health is now one.

25:22.910 --> 25:26.230
And if we damage one more time, the max health is zero.

25:26.230 --> 25:33.150
But the problem is that once our max health reaches zero, the message not getting pop up pop up.

25:33.150 --> 25:39.390
Because if we move over to our script and move over to our enemy two script, as you can see, if the

25:39.390 --> 25:44.190
max cell Maxwell is less than or equal to zero, then we call it the type function.

25:44.190 --> 25:48.190
And this function simply printing out this message saying enemy two died.

25:48.230 --> 25:48.950
But the.

25:48.990 --> 25:56.390
But the problem is that once our Maxwell reaches zero, we still not able to notice that that message

25:56.510 --> 25:59.270
just getting pop up or that type function.

25:59.270 --> 26:05.990
So what we gonna do to, uh, just, uh, to fix these bugs, we will get out of play mode instead of

26:05.990 --> 26:08.670
checking with zero, we're going to check with one.

26:08.670 --> 26:11.990
So it's going to be a one more ahead unit.

26:11.990 --> 26:14.390
So that's why we're going to check right over here.

26:14.390 --> 26:17.710
If the Maxwell is lesser than or equal to one.

26:18.150 --> 26:20.470
So now the function should be pop up.

26:20.470 --> 26:24.110
So let's press down Ctrl s now and let's move over to unity.

26:24.150 --> 26:25.870
You will see one once.

26:25.870 --> 26:33.630
We just gonna attack on uh on into this enemy two game object on uh, on to on.

26:34.590 --> 26:35.150
Sorry.

26:35.550 --> 26:41.280
Uh, once we're gonna damage this enemy two game object three times, you will see the message that's

26:41.280 --> 26:43.640
going to pop up says enemy two died.

26:43.640 --> 26:44.840
So let's see that.

26:44.840 --> 26:47.120
So make sure you select your console tab.

26:47.120 --> 26:49.480
And let's click on this play button in the top.

26:49.480 --> 26:52.880
And let's damage this enemy two game object three times.

26:52.880 --> 26:59.040
So as soon as our max health of this enemy two game object just reaches zero, then die function just

26:59.040 --> 27:03.080
gonna call out and we do know what we're doing inside that die function.

27:03.080 --> 27:06.040
We simply printing out enemy two game object died.

27:06.120 --> 27:10.680
So if I just get closer to this enemy two game object and damage it.

27:10.680 --> 27:12.320
So the max is now two.

27:12.360 --> 27:15.840
And if we damage one more time, max health, we can see one.

27:15.840 --> 27:23.160
And if we damage third time, we can see by now the max health just getting stuck at one.

27:23.160 --> 27:25.000
But we're getting a message.

27:25.000 --> 27:29.640
So if we move over to our console tab we can see a message just gets pop up.

27:29.640 --> 27:31.280
Says enemy two died.

27:31.280 --> 27:33.280
So basically it's working fine.

27:33.280 --> 27:39.800
So instead of checking with zero, you can check with uh, you can check with, uh, you can simply

27:39.800 --> 27:42.120
say you can, uh, check with one.

27:42.120 --> 27:47.480
And I also want to set the max cell value to zero instead of setting it to one.

27:47.480 --> 27:49.960
So what we will do, we will get out of play mode.

27:49.960 --> 27:52.520
And then we're going to move over to our script.

27:52.520 --> 27:59.600
And once our max cells become less than or equal to one, I also want to set the max cell to zero.

27:59.600 --> 28:05.520
So what I'm going to do I'm going to set max health, max health equal to zero since we're going to

28:05.520 --> 28:07.120
show this up in the UI.

28:07.160 --> 28:08.720
So that's why we're doing it.

28:08.720 --> 28:14.920
And now if I press control S on my keyboard and then move over to our script, you will see once we

28:14.920 --> 28:20.760
just gonna attack on this, uh, enemy two game object three times, it's just gonna lose all of its

28:20.760 --> 28:21.040
health.

28:21.040 --> 28:26.880
And this max health is just gonna be zero right away once it loses all of his health.

28:26.960 --> 28:29.320
So let's have a look on this as well.

28:29.320 --> 28:33.320
So let's click on this play button in the top in order to play our game.

28:33.320 --> 28:34.960
And let's check that out.

28:35.200 --> 28:38.530
So once our max is just gonna be zero of this anime.

28:38.570 --> 28:39.650
Two game object.

28:39.650 --> 28:44.370
Then the message just going to pop up because we're calling the die function and die function.

28:44.370 --> 28:48.730
Simply printing out the message in the console tab says anime two die.

28:48.770 --> 28:51.370
So let's get closer and let's attack three times.

28:51.410 --> 28:53.970
One, two and three.

28:54.010 --> 28:56.050
We can see the message just gets pop up.

28:56.050 --> 28:58.490
Anime two died in our console tab.

28:58.650 --> 29:05.050
And if we move over to Inspector by selecting this anime two GameObject in the hierarchy, we can see

29:05.050 --> 29:05.730
the Maxhealth.

29:05.730 --> 29:07.050
We just set it to zero.

29:07.090 --> 29:10.890
As soon as this anime two game object loses all of his health.

29:10.930 --> 29:12.690
So I hope you get the idea.

29:12.690 --> 29:14.130
And also, we need to play.

29:14.170 --> 29:20.490
Uh, basically we need to play the heart animation clip, uh, heart animation clip of this anime to

29:20.530 --> 29:21.570
game object.

29:21.570 --> 29:24.610
So so it's gonna play that animation clip.

29:24.610 --> 29:30.690
Basically we need to play that once our anime two game objects takes damage from this player game object.

29:30.730 --> 29:34.290
At that moment we need to play that animation clip.

29:34.290 --> 29:38.010
So I hope you get the idea and I'm gonna get out of play mode.
