WEBVTT

00:00.040 --> 00:02.200
Now let's play the heart animation clip.

00:02.200 --> 00:06.080
Once this animated enemy two GameObject takes damage.

00:06.320 --> 00:12.320
So let's open up our enemy two script by double clicking on it, and let's move our move over to that

00:12.320 --> 00:15.960
line of code where we're taking damage and we're taking damage.

00:15.960 --> 00:21.680
As you can see, right over here, we subtracting from our maxhealth this damage amount, basically

00:21.680 --> 00:22.920
we're taking damage.

00:22.920 --> 00:26.280
So now we need to play that animation clip which is the heart.

00:26.280 --> 00:32.040
So if we move over to unity editor and then select this enemy to GameObject in the hierarchy, then

00:32.040 --> 00:35.920
move over to animator tab, we need to trigger this heart parameter.

00:35.920 --> 00:41.400
As you can see, we created earlier and we do know that if we trigger this heart parameter, it's going

00:41.440 --> 00:42.240
to play the heart.

00:42.280 --> 00:44.800
So it's going to play the heart animation clip.

00:44.800 --> 00:49.760
So what we need to do, we basically need to trigger this heart parameter through our code.

00:49.760 --> 00:55.720
And we do know that we have the animation of basically we have the animator component reference.

00:55.720 --> 00:56.600
So let's do that.

00:56.600 --> 00:58.920
So let's move over to that line of code.

00:58.980 --> 01:04.780
So what we will do, we will go to animator and then we're going to use dot set trigger function.

01:04.780 --> 01:06.860
Why are we using this set trigger function.

01:06.860 --> 01:10.820
Because that our parameter is a trigger parameter.

01:10.820 --> 01:14.540
So that's why we need to use this dot set trigger function.

01:14.540 --> 01:20.260
And inside this first bracket in quotation it's going to take the parameter name and make sure you just

01:20.260 --> 01:23.820
pass your correct parameter name, which is hard in my case.

01:23.820 --> 01:26.420
And then I'm going to close that off with semicolon.

01:26.420 --> 01:31.060
And we're going to press down Ctrl S to save our save our script.

01:31.060 --> 01:33.300
And now let's move over to unity.

01:33.300 --> 01:39.340
So as soon as we can damage our enemy to game object you will see this enemy two just going to play

01:39.340 --> 01:43.460
the heart animation clip itself of this enemy two game object.

01:43.460 --> 01:51.300
Once it's going to take damage and once the animation is completely are completely playing.

01:51.500 --> 01:55.460
Basically the enemy heart animation 100% clip play.

01:55.620 --> 01:58.090
Then after it this is enemy to game object.

01:58.090 --> 02:04.010
Just gonna play the walk or attack depending upon where player is after taking damage.

02:04.010 --> 02:06.330
So now let's check that out.

02:06.530 --> 02:10.330
So let's click on this play button in the top in order to play our game.

02:10.330 --> 02:13.850
And let's have a look on it to this anime two game object.

02:13.850 --> 02:17.330
And we can see indeed the heart animation clip is playing.

02:17.970 --> 02:19.890
Uh heart animation is playing.

02:19.890 --> 02:23.690
But it shortly and I really apologize for the noises.

02:23.730 --> 02:29.290
I'm gonna give some, uh, some more amount of health to this anime two game object.

02:29.290 --> 02:31.890
So let's select the anime two game object in the hierarchy.

02:31.890 --> 02:34.290
Let's go to anime two script and the max.

02:34.450 --> 02:38.450
I'm gonna give something like 100 in order to check, so that's why.

02:38.490 --> 02:43.090
So let's click on this play button in the top right now and let's have a look on it.

02:43.370 --> 02:48.930
So as soon as we're gonna damage our enemy two game object, it's gonna play the heart animation clip.

02:48.930 --> 02:55.470
And once our heart animation clip completely played, then it's gonna play the, uh, attack or work,

02:55.470 --> 02:57.470
depending upon where the player is.

02:57.470 --> 03:03.150
So if I damage, as you can notice, it's playing the heart animation clip and after playing it's playing

03:03.150 --> 03:04.070
the attack.

03:04.070 --> 03:08.390
And we also need to play the death animation clip of this anime to game object.

03:08.390 --> 03:14.710
Once this anime two game object loses his health, are loses his, loses his health.

03:14.710 --> 03:16.310
So let's get out of play mode.

03:16.310 --> 03:21.470
And again, I'm gonna give Max health to something around three in order to check that out.

03:21.470 --> 03:26.230
And let's move over to our anime tools and let's move over to die function.

03:26.230 --> 03:30.710
So we printing out that this message, as you can notice right over here.

03:30.710 --> 03:35.430
So after printing out the message, we also want to play that death animation clip.

03:35.430 --> 03:38.950
And we do know to play that we will go to animator component.

03:38.950 --> 03:39.830
And then Dot.

03:39.870 --> 03:43.990
We're going to use this set trigger function and set trigger function.

03:43.990 --> 03:47.870
And inside this bracket we need to pass the trigger parameter.

03:47.870 --> 03:50.630
And we can see the trigger parameter is death.

03:50.630 --> 03:54.530
So in quotation we need to pass and make sure you spell it correct.

03:54.810 --> 03:56.010
Uh, which is that?

03:56.010 --> 03:58.530
And then we're going to close that up with semicolon.

03:58.730 --> 04:03.850
And we also need to disable our box collider 2D of this anime two game object.

04:03.850 --> 04:08.610
So it's not going to take any damage damage at all after this.

04:08.650 --> 04:12.490
Uh, this basically this anime two game object loses all of his health.

04:12.530 --> 04:17.970
Basically, we're doing the same thing as we have done with our anime one script, so you can follow

04:17.970 --> 04:25.010
the same, uh, so you can just, uh, do the same way as we have done with our anime one script.

04:25.130 --> 04:28.690
So firstly, what we will do, we will disable the box Collider 2D.

04:28.690 --> 04:34.250
But before we disable, we will set the rigid body 2D gravity scale to zero.

04:34.250 --> 04:36.570
So it's not going to fall down at all.

04:36.570 --> 04:39.730
And after it we're gonna disable this box Collider 2D.

04:39.730 --> 04:41.930
So it's not going to detect any collision.

04:41.930 --> 04:44.930
Basically it's not gonna take any damage at all.

04:44.930 --> 04:48.930
Once this enemy, uh, two game object loses all of his health.

04:48.930 --> 04:53.760
So we need a reference of this rigid body 2D as well as this box collider 2D.

04:53.920 --> 04:57.760
I guess we have the rigid body 2D reference, so let's check that out.

04:57.760 --> 05:04.240
So we will go to our script and let's go to top of our class so we don't have the reference of it.

05:04.240 --> 05:05.480
So let's grab it.

05:05.480 --> 05:08.760
So first thing we're gonna grab our rigid body 2D.

05:08.760 --> 05:10.320
So let's make it private.

05:10.480 --> 05:13.560
And the component we're looking for is a rigid body 2D.

05:13.600 --> 05:17.000
And we're gonna call it RB or short for rigid body 2D.

05:17.160 --> 05:20.560
And also we need a reference to that box Collider 2D.

05:20.560 --> 05:25.680
So we're gonna make private box Collider 2D box Collider 2D.

05:25.960 --> 05:30.120
And we're gonna call this one box Collider 2D, something like that.

05:30.160 --> 05:30.640
Sorry.

05:30.800 --> 05:33.200
We're going to call it Call Collider 2D.

05:33.240 --> 05:34.880
Let's call it Collider 2D.

05:34.880 --> 05:36.920
And let's close that up with semicolon.

05:36.920 --> 05:43.640
But we're getting a green underline because we already have a Collider 2D name inside this script or

05:43.640 --> 05:44.440
somewhere.

05:44.440 --> 05:47.560
So we can simply put a in front of this private.

05:47.560 --> 05:49.040
We can simply put new.

05:49.040 --> 05:52.020
So it's gonna go, uh, it's gonna go.

05:52.220 --> 05:53.460
It's gonna vanish.

05:53.460 --> 05:59.180
You can simply say, but instead of doing that, I'm going to name this variable to something else.

05:59.180 --> 06:03.580
So let's call it Box Collider 2D with a non capitalized B letter.

06:03.900 --> 06:05.340
So Box Collider 2D.

06:05.340 --> 06:06.780
And what we need to do now.

06:06.780 --> 06:08.740
So we made this field private.

06:08.740 --> 06:12.260
So we're not going to able to see underneath our animator script.

06:12.300 --> 06:13.940
But we need the reference.

06:13.940 --> 06:16.420
So that's why we will move over to start function.

06:16.420 --> 06:24.340
And which we gonna grab all the reference of this rigid body 2D and this box collider 2D as well as

06:24.380 --> 06:25.100
we have done.

06:25.340 --> 06:29.540
Basically as we grab it, our animator component, a component.

06:29.540 --> 06:31.140
So we're gonna do the same thing.

06:31.140 --> 06:35.780
So let's firstly do the uh, let's firstly do with our rigid body 2D.

06:35.780 --> 06:44.460
So let's set uh RB equal to this dot, this dot, this.com object dot get component.

06:44.460 --> 06:49.160
And the component that we want to get gate is a rigid body 2D.

06:49.160 --> 06:52.040
So we're going to pass inside these arrows rigid body 2D.

06:52.080 --> 06:53.840
And let's make this first bracket.

06:53.840 --> 06:57.560
And the second component we're looking for is box Collider 2D.

06:57.560 --> 06:59.200
So let's get that as well.

06:59.200 --> 07:04.240
So we're going to use this dot this dot game object dot get component.

07:04.240 --> 07:07.400
And the component we're gonna take is a box collider 2D.

07:07.400 --> 07:11.800
So we're going to pass this box Collider 2D box Collider 2D.

07:12.000 --> 07:15.920
And then close that up with semicolon and close that up with semicolon.

07:15.920 --> 07:17.920
And we have the box Collider 2D pie.

07:17.960 --> 07:21.200
Now basically we just taking this box Collider 2D.

07:21.240 --> 07:27.280
And now let's store this box Collider 2D into this box Collider 2D variable we created.

07:27.400 --> 07:30.960
Sorry we created up over here as you can see.

07:30.960 --> 07:38.880
So let's store this box Collider 2D into this box Collider sorry into this box Collider 2D.

07:38.920 --> 07:45.240
And let's set equal to this basically which simply taking this box Collider 2D as well rigidbody 2D

07:45.240 --> 07:48.380
and we are storing in corresponding components.

07:48.700 --> 07:55.860
We are storing rigid body 2D as you can see into this RB rb equal to this dot GameObject dot get component

07:55.860 --> 07:59.420
rigid body 2D and we taking second.

07:59.860 --> 08:02.660
Basically we taking our box collider 2D.

08:02.700 --> 08:08.180
Sorry, this one is RB or rigid body 2D and this one is a box collider 2D.

08:08.220 --> 08:11.900
We basically getting it and we storing into this box Collider 2D.

08:11.940 --> 08:15.820
Now we have the rigid body 2D as well as the box Collider.

08:15.820 --> 08:20.300
Basically we have this rigid body 2D as well as this box Collider 2D.

08:20.340 --> 08:24.860
And now what we have to do, we need to set this and we're going to do it through our code.

08:24.860 --> 08:27.940
So let's move over to our die function where we dying.

08:28.060 --> 08:30.580
So I'm going to move over to my die function.

08:30.820 --> 08:32.300
So let's over here.

08:32.300 --> 08:36.060
As you can see we playing the animation clip first which is that.

08:36.060 --> 08:40.780
And after playing that we want to disable our box Collider 2D.

08:40.820 --> 08:45.010
But before we disable it, let's set the gravity scale to zero.

08:45.010 --> 08:46.810
So our enemy two came object.

08:46.850 --> 08:50.250
Not gonna not gonna fall due to our gravity.

08:50.250 --> 08:54.890
So we will go to RB dot basically, which is going over to Rigidbody 2D.

08:54.930 --> 08:57.250
And now we're going to access the gravity scale.

08:57.250 --> 08:59.730
And we're going to set equal to zero f.

08:59.850 --> 09:02.090
So it's not going to fall down at all.

09:02.090 --> 09:05.490
And after that we're going to disable our box Collider 2D.

09:05.490 --> 09:07.730
So it's not going to detect any collision.

09:07.730 --> 09:12.170
So it's not going to play the death animation clip over again and again.

09:12.210 --> 09:15.650
So after basically doing that I really apologize.

09:15.930 --> 09:21.890
After doing that, what we're going to do, we're going to uh, we will go to Box Collider 2D and we're

09:21.890 --> 09:25.690
going to use this dot enable and we're gonna set it to false.

09:25.690 --> 09:26.690
Basically uncheck.

09:26.690 --> 09:30.330
Or you can simply assume that we just disabling that.

09:30.690 --> 09:32.130
And I really apologize.

09:32.530 --> 09:35.170
We're gonna we're gonna set it to false.

09:35.170 --> 09:40.450
False basically means we just disabling that box Collider 2D basically this.

09:40.530 --> 09:44.310
And now we're going to press down control S in order to save our script.

09:44.430 --> 09:47.590
So let's press down control S to save our script.

09:47.670 --> 09:49.670
And now let's move over to unity.

09:49.870 --> 09:50.950
Unity editor.

09:50.950 --> 09:52.390
And it's going to work fine.

09:52.390 --> 09:54.150
So just wait a little moment.

09:54.150 --> 09:58.830
Once the compilation is done, we can just go ahead and play our game.

09:58.870 --> 10:01.190
Firstly, we setting the gravity scale to zero.

10:01.190 --> 10:05.230
So this army to game object not gonna fall down at all with gravity.

10:05.550 --> 10:08.830
And the second thing we just disabling the box Collider 2D.

10:08.830 --> 10:12.070
Once our enemy two GameObject loses all of his health.

10:12.110 --> 10:15.710
So this enemy two GameObject not gonna detect any collision.

10:15.710 --> 10:20.190
So it's not gonna play that animation clip over again and again.

10:20.230 --> 10:25.190
Basically, we're doing the same thing as we have done earlier with Enemy One script.

10:25.190 --> 10:32.230
So just wait a moment and once our compilation is done, we can just go ahead and we can play our game

10:32.230 --> 10:33.510
and also really upload.

10:33.510 --> 10:36.190
This is just taking a little bit longer time.

10:36.190 --> 10:43.490
Now as you can notice where compilation is done and we can just go ahead and we can play our game.

10:43.490 --> 10:47.370
So let's click on this play button in the top in order to play our game.

10:47.570 --> 10:50.010
And let's have a look on this.

10:52.890 --> 10:54.290
So just wait a moment.

10:55.730 --> 11:05.170
And once our, uh, once our, uh, once our game is ready, then we can just go ahead and we can check

11:05.170 --> 11:06.010
that out.

11:06.490 --> 11:12.650
Firstly, we need to get closer to this enemy two game object, or we need to give it a moment to this

11:12.690 --> 11:17.730
enemy two game object in order to approach towards our player game object.

11:17.890 --> 11:20.210
So let's have a look on this by now.

11:20.850 --> 11:21.970
So just wait.

11:23.570 --> 11:29.010
So now if we damage our enemy, we can see it's taking.

11:29.050 --> 11:38.520
And once it's uh, basically uh, once it's, uh, enemy loses all of his health, we can see this anime

11:38.560 --> 11:41.840
to game object is now playing the death animation clip.

11:41.840 --> 11:46.640
And let me show you once again, since it's a basically lagging a little bit.

11:46.640 --> 11:52.240
So I'm gonna get out of play mode and let's click on this play button in the top one more time in order

11:52.240 --> 11:53.400
to check that out.

11:53.720 --> 11:57.920
And I also really apologize for just lagging a little bit.

12:00.400 --> 12:06.840
So I guess so now let's click on this play button in the top in order to play our game one more time.

12:07.360 --> 12:09.880
And we gonna check that out.

12:15.280 --> 12:23.240
So let's get closer to our enemy to Game object, or let's give it a moment to our enemy to game object.

12:23.240 --> 12:30.120
In order to approach towards our player game object, we can see if we damage first time and second

12:30.120 --> 12:32.080
time, and then third time.

12:32.080 --> 12:35.440
As you can see, as soon as it loses all of his health.

12:35.440 --> 12:35.500
Result.

12:35.540 --> 12:39.540
Now this anime two game object just state right away.

12:39.780 --> 12:41.020
And now what we have to do?

12:41.020 --> 12:47.340
We need to destroy this anime to game object after some period of time, once it loses all of his health.

12:47.420 --> 12:49.100
So we will get out of play mode.

12:49.140 --> 12:52.060
To destroy that, we're gonna use the destroy function.

12:52.060 --> 12:55.580
So let's open up our enemy two script by double clicking on it.

12:55.940 --> 12:58.340
And let's move over to this type function.

12:58.340 --> 13:01.660
As you can see, firstly we playing our animation clip.

13:01.660 --> 13:06.420
Then we setting gravity equal to zero and then we disabling the box collider 2D.

13:06.660 --> 13:10.140
So it's not gonna detect any collision at all.

13:10.140 --> 13:12.140
After losing all of his health.

13:12.140 --> 13:15.940
And now what we have to do, we need to destroy it and to destroy.

13:15.940 --> 13:19.900
We're gonna use this destroy function and this function as a first argument.

13:19.900 --> 13:22.900
It's going to take the game object that we want to destroy.

13:22.900 --> 13:24.740
So we want to destroy itself.

13:24.740 --> 13:29.860
So that's why we're going to pass this dot game object basically referencing itself as a.

13:29.860 --> 13:36.280
And the second thing comma, it's going to take the time after how much amount of time you want to destroy.

13:36.280 --> 13:37.840
So I want to destroy it.

13:37.840 --> 13:39.720
Something like after five seconds.

13:39.720 --> 13:44.760
So that's why, as a second argument, I'm gonna put five F, and now I'm going to close that up with

13:44.760 --> 13:45.440
semicolon.

13:45.440 --> 13:48.160
And let's press down Ctrl S to save our script.

13:48.160 --> 13:50.200
And now let's move over to unity.

13:50.200 --> 13:56.920
So after five seconds you will able to notice this enemy two game object just gonna destroy itself after

13:56.920 --> 13:57.920
five seconds.

13:58.120 --> 14:02.000
So just wait a moment and once it's done, we can check that out.

14:06.200 --> 14:11.160
So now the compilation is done and we are ready to play our game.

14:11.560 --> 14:15.400
So let's click on this play button in the top in order to play our game.

14:15.400 --> 14:17.080
And let's check that out.

14:25.000 --> 14:30.720
So now let's get closer to our game object First Army two.

14:30.760 --> 14:35.030
And we can see one, two three.

14:35.790 --> 14:36.510
Sorry, three.

14:36.550 --> 14:38.230
And now loses all of his cell.

14:38.470 --> 14:44.310
And after five seconds we can notice the enemy two GameObject just destroy itself.

14:44.430 --> 14:48.510
And we cannot able to in the scene view as well as in the hierarchy.

14:48.710 --> 14:54.710
And if I move over to my hierarchy, as we as you can see right over here, we're not able to notice

14:54.710 --> 15:00.230
our enemy two GameObject after five seconds, it just destroyed it itself.

15:00.310 --> 15:05.150
So I hope you get the idea that how you can do it and I'm gonna get out of play mode.

15:05.190 --> 15:06.510
Basically we have that.

15:06.670 --> 15:14.830
We basically we have done we have done the same thing as we have done with our, uh, with our enemy

15:14.830 --> 15:16.310
pawn script earlier.

15:16.310 --> 15:22.510
So you can just, uh, follow the same script so you can just copy and paste it, uh, inside your enemy

15:22.550 --> 15:24.910
to escape from your enemy one script.

15:25.070 --> 15:27.430
Or you can just, uh, follow this as well.

15:27.470 --> 15:28.310
You can do that.

15:28.310 --> 15:30.870
I hope you get the idea that how you can do it.
