WEBVTT

00:00.040 --> 00:04.960
We simply printing out a message saying that enemy one died instantly.

00:04.960 --> 00:09.200
Instead of printing out message, we need to play the death animation clip.

00:09.200 --> 00:14.480
So if I select my enemy one GameObject in the hierarchy and then move over to animator tab.

00:14.520 --> 00:17.880
As you can see, we have the Death animation clip.

00:17.880 --> 00:20.280
So we need to trigger this death parameter.

00:20.640 --> 00:25.040
So we do know that if we trigger it it's going to play that animation clip.

00:25.040 --> 00:31.680
So what we will do we will open up our enemy one script and we will go to our update function instead

00:31.680 --> 00:38.560
of doing over here we don't want to check every single frame or basically if we just call this die function.

00:38.560 --> 00:43.000
So inside this die function we basically want to trigger that parameter.

00:43.000 --> 00:45.720
So let's trigger that parameter first.

00:45.720 --> 00:48.240
And after that we're going to take a look on that.

00:48.480 --> 00:53.720
So firstly we need a reference of this animator component of this enemy one game object.

00:53.720 --> 00:55.440
And we do know that we have it.

00:55.440 --> 00:59.920
So we will simply open up enemy one script and let's go to die function.

00:59.920 --> 01:01.930
And inside this function.

01:01.930 --> 01:05.810
After printing out message, I want to trigger that parameter.

01:05.810 --> 01:11.570
And we do know that as soon as we trigger it, it's going to play the death animation clip, which we

01:11.570 --> 01:12.610
saw earlier.

01:12.610 --> 01:18.450
So we will go to animator component, and we're going to use this set trigger function in order to trigger

01:18.450 --> 01:19.410
that parameter.

01:19.570 --> 01:21.970
Why are we using this trigger function.

01:21.970 --> 01:28.650
Because if we move over to unity and we can notice that this parameter is a trigger parameter.

01:28.650 --> 01:33.450
So firstly we are moving over to this animator component of this anime one game object.

01:33.450 --> 01:36.890
And after that we are just using this set trigger function.

01:36.890 --> 01:42.610
And inside the inside this brackets in quotation it's going to take the parameter name.

01:42.610 --> 01:44.410
So the parameter name is death.

01:44.410 --> 01:47.690
So we need to pass the death and make sure you spell it correct.

01:47.690 --> 01:50.010
Else it's not going to work at all.

01:50.010 --> 01:52.570
And after that we will close that off with semicolon.

01:52.570 --> 01:55.890
And now we're going to press down Ctrl S to save our escape.

01:56.010 --> 02:02.620
And if we move over to unity and then we loses all of our health, you will see this anime one game

02:02.660 --> 02:03.180
object.

02:03.180 --> 02:07.060
Just gonna play the death animation clip over again and again.

02:07.100 --> 02:07.540
Why?

02:07.700 --> 02:13.220
Because if we move over to our update function in update function, we are calling the die function

02:13.220 --> 02:16.460
and we do know what we're doing inside that function.

02:16.460 --> 02:22.700
So this type function just going to call over again and again means the death animation clip just gonna

02:22.700 --> 02:24.780
play over again and again.

02:24.820 --> 02:25.740
Let me show you.

02:26.100 --> 02:32.900
So if I move over to unity and then click on this play button, you will see that once this anime one

02:32.900 --> 02:40.780
just gonna loses all of his health, uh, than this death animation clip just gonna play over again

02:40.780 --> 02:43.540
and again of this anime one game object.

02:43.540 --> 02:45.020
So let me show you first.

02:45.020 --> 02:49.180
So let's get in attack range and try to damage this anime one.

02:49.180 --> 02:53.340
So if I damage it we can see that now it's died.

02:53.380 --> 02:59.300
And but the problem is that as you can notice, the death animation clip just playing over again and

02:59.300 --> 02:59.700
again.

02:59.740 --> 03:00.100
Why?

03:00.260 --> 03:06.120
Because if we move over to a script and then go over to update function, we do know that this update

03:06.120 --> 03:08.080
function runs every single frame.

03:08.080 --> 03:12.680
So every single frame we are checking if the max cell is less than or equal to zero.

03:12.720 --> 03:18.000
If that is the case, then we are calling the die function and die function, simply triggering that

03:18.000 --> 03:21.800
parameter which is dead, and it's going to trigger every single frame.

03:21.840 --> 03:25.320
Since we're calling this die function inside this update function.

03:25.320 --> 03:31.040
So that's why we're going to remove this from here to our Takedamage function.

03:31.040 --> 03:36.000
Inside this Takedamage function we're going to move it in inside over here.

03:36.280 --> 03:39.720
So we will get out of play mode and let's remove that.

03:39.720 --> 03:41.400
So I'm going to get out of play mode.

03:41.400 --> 03:43.320
And let's move over to our scape.

03:43.320 --> 03:45.600
And let's move over to update function.

03:45.600 --> 03:47.760
And let's remove this over here.

03:47.920 --> 03:51.560
Instead of doing that we're going to call the die function here.

03:51.560 --> 03:53.480
So let's call the die function here.

03:53.760 --> 03:55.920
So we also check in right over here.

03:55.920 --> 03:57.560
If the max health of enemy.

03:57.680 --> 04:03.090
If it's less than or equal to zero then what we're doing we with we just stop taking.

04:03.130 --> 04:03.650
Damage.

04:03.650 --> 04:09.490
So we also need to call the die function once our enemy one just loses all of his health.

04:09.490 --> 04:11.410
So we're going to call the die function here.

04:11.570 --> 04:14.930
And let's make first bracket and then close that up with semicolon.

04:14.930 --> 04:18.010
And now we're going to press down Ctrl S to save our escape.

04:18.010 --> 04:23.210
And now that death animation clip not gonna play over again and again.

04:23.250 --> 04:29.730
So since the Takedamage function we're not calling inside our update function, which update function

04:29.730 --> 04:30.970
runs every single frame.

04:30.970 --> 04:37.770
So that's why that function, basically that death parameter just triggering over again and again.

04:37.770 --> 04:40.250
And we just removed it totally by now.

04:40.250 --> 04:42.370
And it should be fine by now.

04:42.370 --> 04:43.650
But let's have a look.

04:43.650 --> 04:45.570
So I'm going to select my console tab.

04:45.570 --> 04:47.450
And let's click on this play button.

04:47.450 --> 04:52.610
And we're gonna notice a strange things underneath our enemy one script.

04:52.610 --> 04:53.650
You will see that.

04:54.610 --> 05:00.810
So just wait a little moment and just wait a moment.

05:00.810 --> 05:06.580
So if we get in attack range and then attack one, we can see the maxhealth is now two.

05:06.620 --> 05:10.740
And if we attack one more time, maxhealth is became one.

05:10.740 --> 05:14.340
And if we attack one more time, Maxhealth is now zero.

05:14.340 --> 05:20.380
But the problem is that if I pause my game and then move over to my console tab, we cannot able to

05:20.380 --> 05:22.020
see that enemy one died.

05:22.060 --> 05:23.900
Messages gets popped up.

05:23.940 --> 05:28.420
Even though our max health of this enemy one GameObject reaches zero.

05:28.660 --> 05:31.700
So it's still that message just not getting pop up.

05:31.700 --> 05:40.020
But if we attack one more time, uh, time on top in this, uh, basically, if we attack on this enemy

05:40.060 --> 05:43.540
one GameObject, then you will see that message just gonna pop up.

05:43.540 --> 05:47.260
So I'm going to click on this pause button to unpause my game.

05:47.260 --> 05:48.140
And let's have a look.

05:48.140 --> 05:52.500
If I just attack one more time and now we can see the message.

05:52.500 --> 05:53.540
So sorry.

05:53.700 --> 05:56.500
If we attack we can see the message just gets pop up.

05:56.500 --> 06:01.580
If I pause my game and then move over to console tab, we can see now buy now.

06:01.790 --> 06:04.470
And you may want that message just gets pop up.

06:04.470 --> 06:05.870
So basically what we're gonna do.

06:05.950 --> 06:09.270
Instead of checking with zero we're going to check with one.

06:09.270 --> 06:10.630
So that is the thing.

06:10.630 --> 06:14.790
So we will get out of play mode and let's move over to our script.

06:14.790 --> 06:18.070
Instead of checking zero we're going to check with one.

06:18.070 --> 06:20.990
And now it's gonna work as fine.

06:20.990 --> 06:22.670
It's gonna work fine by now.

06:22.670 --> 06:23.750
So let's have a look.

06:23.750 --> 06:26.590
So we're going to press down Ctrl S to save our script.

06:26.590 --> 06:28.590
And now let's move over to unity.

06:28.870 --> 06:31.270
So it should work fine by now.

06:32.790 --> 06:34.030
So let's have a look.

06:34.030 --> 06:40.990
So as soon as our maxhealth of this anime one just gonna reach zero, then that message just going to

06:40.990 --> 06:43.470
pop up since we just checking with one.

06:43.470 --> 06:44.870
So that is the reason.

06:44.870 --> 06:47.790
So we gotten back and we just got it fixed.

06:47.790 --> 06:52.190
So let's click on this play button in the top in order to play our game.

06:52.190 --> 06:54.150
And let's take a look on this.

06:54.150 --> 06:56.910
So as soon as this enemy one just lose.

06:57.230 --> 06:59.830
Enemy one just gonna lose all of his health.

06:59.910 --> 07:06.120
Then message just gonna pop up underneath our control tab says enemy one died and then it's going to

07:06.120 --> 07:09.440
play that enemy one, that animation clip.

07:09.440 --> 07:17.760
So by so if I attack three times one, two and three, we can see that if we move over to our console

07:17.760 --> 07:21.560
tab, we can see enemy one died, message just gets popped up.

07:21.560 --> 07:27.240
And also the parameter just gets triggered which is playing the death animation clip.

07:27.240 --> 07:34.560
As soon as this enemy one just get, uh, loses all of his health because if it loses all of his health,

07:34.560 --> 07:36.840
as you can see, we're checking over here.

07:36.880 --> 07:38.720
Then we're calling the die function.

07:38.720 --> 07:44.280
What die function simply doing is firstly printing out the message in the console says enemy one died,

07:44.360 --> 07:45.720
as you can notice.

07:45.720 --> 07:51.000
And after that we're just going over to animator component and we're just triggering that parameter

07:51.000 --> 07:56.680
simply we're just moving over to this animator component of this enemy one game object and then just

07:56.680 --> 07:58.360
triggering this state parameter.

07:58.360 --> 08:04.300
And we do know that if we trigger it, we can see that animation just playing over again and again.

08:04.460 --> 08:10.740
But the problem is that if we attack on this enemy one game object, still this enemy one just taking

08:10.740 --> 08:14.060
damages and it's playing the death animation clip.

08:14.060 --> 08:15.900
So we need to stop doing that.

08:15.900 --> 08:21.340
So basically what we have to do, we need to disable the collider of this enemy one game object.

08:21.340 --> 08:27.180
And we do know that if we disable the collider of this enemy one game object, it's not going to detect

08:27.180 --> 08:28.220
any collision.

08:28.220 --> 08:34.540
So it's gonna not gonna take any damage anymore on that takedamage function.

08:34.540 --> 08:36.220
Not gonna call at all.

08:36.380 --> 08:43.740
So basically we need to disable this box Collider 2D of this enemy one, basically this Collider 2D.

08:43.740 --> 08:45.300
So we need to disable that.

08:45.300 --> 08:48.820
So this enemy one not gonna detect any collision.

08:48.820 --> 08:50.380
So let's get out of play mode.

08:50.820 --> 08:57.620
To disable that we need a reference of this box Collider 2D component of this enemy one game object.

08:57.700 --> 09:01.060
Then we can just disable that so we will open up.

09:01.060 --> 09:07.270
But the problem is that if we go ahead and then click on this play button, as soon as we disable this

09:07.270 --> 09:10.630
box Collider 2D manually, you will see this.

09:10.670 --> 09:11.470
Play this.

09:11.470 --> 09:14.230
Sorry, sorry really sorry.

09:14.230 --> 09:18.030
This anime one just gonna fall down due to our gravity.

09:18.030 --> 09:20.990
So if I just manually disable this box collider.

09:20.990 --> 09:26.750
So if I select my anime one GameObject in the hierarchy, then go over to Inspector, then Box Collider

09:26.750 --> 09:29.750
2D and then uncheck basically disable that.

09:29.790 --> 09:34.830
Well, as you can see, as soon as we disable it, it just passes through this ground.

09:34.830 --> 09:35.230
Why?

09:35.270 --> 09:39.470
Because uh, that collider just not detecting any collision.

09:39.470 --> 09:42.750
So that's why it just falls through this ground.

09:42.750 --> 09:48.790
So what we need after disabling this box Collider 2D, we need to set the gravity scale to zero.

09:48.790 --> 09:55.070
So if we move over to this rigidbody 2D component of this animation game object and and then move over

09:55.070 --> 09:58.110
to gravity scale, we can see we set it to three.

09:58.110 --> 09:59.470
So we're gonna set it to zero.

09:59.470 --> 10:01.830
So it's not gonna fall down at all.

10:01.830 --> 10:06.920
So we need a reference of this rigid body 2D as well as this box collider 2D.

10:06.960 --> 10:08.840
Then we can just set that up.

10:08.960 --> 10:11.320
So let's get out of play mode.

10:11.320 --> 10:14.680
And let's open up anime one script by double clicking on it.

10:14.680 --> 10:19.080
And let's go to the top of our class and let's declare those variable.

10:19.120 --> 10:21.840
Basically we need to graph reference of those.

10:21.840 --> 10:25.280
So the first thing we're gonna grab our box Collider 2D.

10:25.440 --> 10:30.480
So let's make a private uh the component we're looking for is a box Collider 2D.

10:30.480 --> 10:34.400
So we're going to type that and let's call it something like Box Collider 2D.

10:34.560 --> 10:36.400
And it doesn't need to be public.

10:36.600 --> 10:39.480
We're gonna grab the reference in this start function.

10:39.480 --> 10:40.280
So that's why.

10:40.600 --> 10:46.000
And the second component or the reference we looking for is our rigidbody 2D.

10:46.000 --> 10:47.880
So we're going to create a private.

10:47.880 --> 10:51.240
And the component we're looking for is a rigid body 2D.

10:51.240 --> 10:54.640
And we can call this one RB short for rigid body.

10:54.680 --> 10:58.440
You can simply say and now let's move over to this start function.

10:58.440 --> 11:01.440
So this start function get call in the start of the game.

11:01.440 --> 11:04.130
So in the start of the game we need to get the reference.

11:04.130 --> 11:10.210
Basically we need to take this rigidbody 2D as well as this box collider 2D component of this enemy

11:10.250 --> 11:11.330
one game object.

11:11.330 --> 11:12.410
So let's do that.

11:12.690 --> 11:16.450
So firstly we're gonna grab the reference box Collider 2D.

11:16.810 --> 11:18.650
Uh you can just do it.

11:18.690 --> 11:24.250
Uh, you don't need to, uh, make it in order in a order, certain order.

11:24.250 --> 11:26.490
You just make it wherever you want.

11:26.530 --> 11:29.890
Inside this start function, it doesn't need to be in order.

11:30.290 --> 11:35.330
So firstly, we want to grab the reference of our you can simply say box Collider 2D.

11:35.330 --> 11:36.330
So I'm going to type this.

11:36.330 --> 11:40.370
This dot GameObject basically means it just referencing itself.

11:40.530 --> 11:44.690
And we're going to use this dot get component in order to get the component.

11:44.690 --> 11:46.450
And we need to make these arrows.

11:46.450 --> 11:50.490
And inside these arrows we need to pass the component that we're looking for.

11:50.490 --> 11:52.730
So we're looking for our box Collider 2D.

11:52.730 --> 11:57.170
So we're going to type this box Collider 2D and then make this first bracket.

11:57.170 --> 11:59.810
And now we're going to close that up with semicolon.

11:59.810 --> 12:03.620
And now what we're going to do we're going to store this box Collider 2D component.

12:03.820 --> 12:06.420
Uh, basically we're just using this dot GameObject.

12:06.420 --> 12:08.780
Basically it's just referencing itself.

12:08.780 --> 12:12.780
So the animation script is attached to this anime one game object.

12:12.780 --> 12:18.100
So this GameObject, they're basically referencing this anime, one game object itself.

12:18.100 --> 12:22.100
And we're using Dot get component in order to create the component.

12:22.100 --> 12:24.980
So now we have this box Collider 2D component.

12:24.980 --> 12:29.620
As you can see in the in inside our start function.

12:29.620 --> 12:35.900
As you can see now we have it and we're going to store it into this box Collider 2D variable that we

12:35.940 --> 12:38.540
created up here as you can notice.

12:38.540 --> 12:43.940
So after taking that we're gonna store it into this box Collider 2D variable.

12:43.980 --> 12:45.700
Let's set equal to this.

12:45.740 --> 12:46.900
Basically what we're doing.

12:46.900 --> 12:51.740
We simply just getting this box collider 2D component of this anime one game object.

12:51.740 --> 12:58.620
And then we're storing that into this box Collider 2D variable we created up over here as you can see.

12:58.820 --> 13:01.620
And we're gonna do the same thing with this rigid body.

13:01.700 --> 13:03.350
So we're going to do the same thing.

13:03.710 --> 13:06.670
So what we will do we're going to store it into this RB.

13:06.710 --> 13:12.190
So we will set RB equal to this dot GameObject which is referencing itself.

13:12.310 --> 13:15.310
And the component we're looking for is a component.

13:15.310 --> 13:15.830
Sorry.

13:15.870 --> 13:18.030
We need to type this dot get component.

13:18.030 --> 13:21.110
And the component will be looking for is a rigid body 2D.

13:21.110 --> 13:23.270
So we're going to type this rigid body 2D.

13:23.310 --> 13:26.790
And let's make this first bracket and then close that up with semicolon.

13:26.990 --> 13:32.270
So we basically just grabbing this rigid body 2D component of this enemy one game object.

13:32.270 --> 13:40.830
And after that we storing that into this RV, that RV variable which is a rigid body 2D variable or

13:40.870 --> 13:46.310
a container type, you can simply say you can assume that we're storing into this RB.

13:46.550 --> 13:49.630
And we also taking our box collider 2D component.

13:49.630 --> 13:53.110
And we're storing into this box Collider 2D variable.

13:53.110 --> 13:55.990
As you can see inside our start function.

13:55.990 --> 14:00.510
Now we have it this box Collider 2D as well as this rigid body 2D.

14:00.550 --> 14:03.050
And now we are ready to set that up.

14:03.050 --> 14:06.530
So let's move over to our die function.

14:06.530 --> 14:07.090
Where are we?

14:07.130 --> 14:08.450
Doing so over here.

14:08.450 --> 14:11.170
As you can see we're triggering the parameter.

14:11.170 --> 14:17.450
So what we're going to do now over here uh firstly we will disable our box collider 2D.

14:17.610 --> 14:20.810
But before we disable let's set the gravity scale to zero.

14:20.810 --> 14:22.330
So we will go to RB.

14:22.370 --> 14:24.170
RB basically means rigid body.

14:24.170 --> 14:28.010
We just going over to that and we're going to access the gravity scale.

14:28.210 --> 14:30.770
And we're going to set equal to zero f.

14:30.810 --> 14:32.930
And let's close that up with semicolon.

14:32.930 --> 14:38.850
So we simply just moving over to this rigid body 2D component of this anime one game object and then

14:38.850 --> 14:41.490
accessing this gravity scale right over here.

14:41.490 --> 14:43.330
And we're setting equal to zero.

14:43.370 --> 14:49.370
As you can see now this anime one game object not going to fall down at all.

14:49.370 --> 14:56.410
And we also need to disable this box Collider 2D once this anime one game object loses all of his health.

14:56.610 --> 15:02.050
And so after setting gravity to zero, we're gonna disable that box Collider 2D.

15:02.170 --> 15:07.620
So we will go to Box Collider 2D where we store it, and then we're going to use the start.

15:07.620 --> 15:10.180
And then we're going to use this dot enable.

15:10.180 --> 15:12.300
And we can set equal to false.

15:12.340 --> 15:16.020
Set equal to false basically means we just disabling that.

15:16.380 --> 15:21.060
Or you can simply unchecking or checking if you set it to true something like that.

15:21.060 --> 15:24.340
It's basically means checked means you just setting it to true.

15:24.700 --> 15:28.020
Uh or you just enabling your box collider 2D.

15:28.060 --> 15:32.900
But if you set dot enable to false basically means you just disabling that.

15:32.900 --> 15:38.380
Or you can assume that we just unchecking or disabling this box Collider 2D.

15:38.620 --> 15:42.900
So as soon as our enemy GameObject just gonna loses all of his health.

15:42.940 --> 15:46.780
Firstly, we printing out the message in the console tabs enemy.

15:47.420 --> 15:53.260
As you can see, after that we playing the anime Death animation clip, and then we setting the gravity

15:53.260 --> 15:54.300
scale to zero.

15:54.300 --> 15:59.380
And after that we just setting box collider 2D dot enable to false.

15:59.380 --> 16:02.460
Basically we just disabling our box Collider 2D.

16:02.580 --> 16:05.670
So it's not gonna take damage after.

16:05.670 --> 16:09.430
Once our enemy won, game object loses all of his L.

16:09.430 --> 16:12.590
So it's not going to check for any collision at all.

16:12.590 --> 16:16.750
Once our box collider 2D enable enabled to false.

16:16.870 --> 16:19.910
And now we're going to press down Ctrl S to save our script.

16:19.910 --> 16:21.590
And let's move over to unity.

16:22.030 --> 16:26.310
So as soon as this enemy one GameObject just loses all of his L.

16:26.350 --> 16:31.430
Firstly, we're setting the gravity scale to zero, so it's not going to fall down at all.

16:31.430 --> 16:34.110
And after that we disabling the box Collider 2D.

16:34.110 --> 16:40.190
So it's not going to detect any collision means this enemy game object just gonna be fine.

16:40.190 --> 16:41.070
So let's have a look.

16:41.070 --> 16:45.110
So I'm going to click on this play button in the top in order to play my game.

16:45.270 --> 16:47.270
And let's have a look on this.

16:47.270 --> 16:55.630
So as soon as this enemy one enemy one GameObject Maxhealth hits zero, you will see that that animation

16:55.630 --> 16:57.590
just gonna play right away.

16:57.750 --> 17:04.400
So let's get in attack range and let's attack on this enemy one, two and three we can see.

17:04.440 --> 17:11.800
And now if we just, uh, attack, we cannot see this enemy one just playing the death animation clip

17:11.800 --> 17:12.400
by now.

17:12.440 --> 17:12.880
Why?

17:13.080 --> 17:17.760
Because if we select our enemy one in the hierarchy, then go over to Inspector.

17:17.760 --> 17:20.720
We can see we just uncheck the box Collider 2D.

17:20.720 --> 17:25.640
So that's why this enemy one not detecting any collision at all.

17:25.640 --> 17:31.480
And also we can see if we move over to this rigidbody 2D component, we can see that we just set it

17:31.480 --> 17:33.520
to zero gravity scale to zero.

17:33.560 --> 17:35.840
As you can notice right over here.

17:36.120 --> 17:38.800
So I hope you get the idea that how you can do it.

17:38.800 --> 17:43.720
And after some period of time we also need to destroy this enemy itself.

17:43.720 --> 17:45.280
So let's get out of play mode.

17:45.280 --> 17:45.760
For that.

17:45.760 --> 17:48.160
We're gonna open up our enemy one script.

17:48.160 --> 17:54.000
So let's open that up by double clicking on it and let's move over to die function right over here.

17:54.000 --> 17:56.880
So after some period of time we need to destroy.

17:57.080 --> 18:00.680
And in order to destroy we need to use this destroy function.

18:00.680 --> 18:02.760
And this destroy function in brackets.

18:02.760 --> 18:05.770
It's going to take the game object that we want to destroy.

18:05.930 --> 18:08.770
So we want to destroy itself or the enemy.

18:08.810 --> 18:10.330
One game object itself.

18:10.330 --> 18:12.970
So we're going to pass this start game object.

18:13.010 --> 18:16.490
It's basically referencing the enemy game object itself.

18:16.490 --> 18:19.050
And then we're going to close that off with a semicolon.

18:19.050 --> 18:21.930
But if we don't specify sorry.

18:21.970 --> 18:28.570
If we don't specify as a second argument the time then our enemy one just going to destroy right away

18:28.770 --> 18:35.730
and which we really don't want to, uh, be, uh, don't want which we really don't want.

18:35.730 --> 18:40.370
So that's why as a second argument, comma, we can specify the time.

18:40.370 --> 18:43.770
So after something like five second I just want to destroy.

18:43.770 --> 18:47.210
So that's why as a second argument I'm going to put five f.

18:47.250 --> 18:49.890
Or you can simply assume five seconds.

18:49.930 --> 18:53.210
And now I'm going to press down Ctrl S to save my script.

18:53.210 --> 18:54.850
And let's move over to unity.

18:55.050 --> 19:01.330
And if you don't assign the second argument then in your case the enemy one game object just gonna destroy

19:01.370 --> 19:04.230
itself immediately, which we don't want.

19:04.270 --> 19:07.790
So that's why as a second argument, we just pass the time.

19:07.950 --> 19:10.030
And now we're going to take a look on it.

19:10.150 --> 19:14.150
So let's click on this play button in the top in order to play our game.

19:14.150 --> 19:20.590
And let's attack on this enemy one game object three times in order to destroy this enemy completely

19:20.790 --> 19:22.230
and before it destroy.

19:22.270 --> 19:28.590
Firstly, it's gonna play that animation clip and after something like five seconds, it's gonna destroy

19:28.590 --> 19:29.310
itself.

19:29.310 --> 19:31.710
So let's get in attack range.

19:31.870 --> 19:37.790
And if we just, uh, three times, we can see by now it's played the death animation clip.

19:37.790 --> 19:40.110
And after five seconds you will see a.

19:40.150 --> 19:45.910
We can notice that after five seconds, that enemy one game object get destroy itself.

19:45.910 --> 19:51.230
And we cannot see in this in view as well as as well as in the hierarchy.

19:51.230 --> 19:58.630
So if I move over to my hierarchy, we cannot see our enemy one because it just destroy itself after

19:58.630 --> 20:01.190
five seconds that we specified the time.

20:01.190 --> 20:04.400
So I'm gonna get out of play mode, so I hope you get the idea.

20:04.440 --> 20:06.000
Firstly, we're just damaging.

20:06.200 --> 20:13.080
And once it's taking damage, we're checking if it's hit zero or something like less than one or equal

20:13.120 --> 20:16.240
or lesser than 1 or 0, something like that.

20:16.280 --> 20:21.360
If that is the case, then we're calling the die function and die function simply doing this thing.

20:21.400 --> 20:26.600
Firstly, it's printing out the message, then playing the animation clip and setting the gravity scale

20:26.640 --> 20:29.360
to zero so it's not gonna fall down at all.

20:29.480 --> 20:32.520
And after that we just disabling the box Collider 2D.

20:32.560 --> 20:39.720
So that's why it's not detecting any collision means even after if we disable that, then if we just

20:39.760 --> 20:46.360
attack on this enemy one GameObject, it's gonna and it's not gonna take any damage at all since we

20:46.360 --> 20:47.680
just disable that box.

20:47.680 --> 20:54.200
Collider 2D, which is responsible for detecting collision, and after five seconds we destroying the

20:54.200 --> 20:56.600
GameObject itself, as you can see.

20:56.680 --> 20:59.520
So I hope you get the idea that how you can do it.

20:59.880 --> 21:04.680
And I'm going to press down Ctrl s on my keyboard in order to save my project.
