WEBVTT

00:00.040 --> 00:03.520
We also need to play the heart animation clip.

00:03.520 --> 00:09.840
So once this enemy one GameObject takes damage, it's need to play the heart animation clip.

00:09.840 --> 00:16.160
So if you if we select our enemy one GameObject in the hierarchy, then move over to animator tab.

00:16.640 --> 00:18.680
So we need to trigger this heart parameter.

00:18.680 --> 00:23.680
And we do know that if we trigger it, it's gonna play the heart animation clip.

00:23.680 --> 00:26.440
So before we do scripting let me show you.

00:26.440 --> 00:29.840
So let's click on this play button in the top to play our game.

00:30.120 --> 00:36.680
And if we trigger this heart parameter manually, as soon as we're gonna trigger it, this enemy one

00:36.680 --> 00:39.640
just gonna play the heart animation right away.

00:39.800 --> 00:46.120
And after playing that, it's gonna move over to this arrow fire or a idle animation clip, depending

00:46.120 --> 00:48.080
upon where player is.

00:48.240 --> 00:54.320
If the player is inside attack range, then it's gonna play the arrow fire right away.

00:54.880 --> 00:58.080
And if it's not, then it's gonna play the idle one.

00:58.080 --> 01:04.880
So now if I select my enemy one in the hierarchy, then move over to animator tab and then try to trigger

01:04.880 --> 01:06.680
this heart parameter manually.

01:06.680 --> 01:11.180
We can see it's playing the heart animation clip as soon as we're triggering.

01:11.180 --> 01:17.420
So instead of doing manually, we're going to do it once this anime one game object takes damage.

01:17.420 --> 01:22.940
So let's get out of play mode, and let's open up the anime one script by double clicking on it.

01:22.940 --> 01:28.300
And we do know that we need a reference of this animator component, and we have it already.

01:28.300 --> 01:33.900
So what we're going to do now, we're going to move over to that line, that line of code, or in a

01:33.900 --> 01:37.020
function where we just are taking damage.

01:37.020 --> 01:39.220
So we're taking damage right over here.

01:39.220 --> 01:44.020
As you can see, we're just subtracting from our max health this damage amount.

01:44.180 --> 01:48.220
So after taking damage we also need to play that animation clip.

01:48.220 --> 01:51.180
So we will go to our animator component.

01:51.180 --> 01:54.620
So let's go to animator component Animator.

01:54.620 --> 01:59.340
And we're going to use this start trigger function a set trigger.

01:59.340 --> 02:00.980
And this function in brackets.

02:00.980 --> 02:06.300
It's going to take uh the parameter name inside in quotation inside this brackets.

02:06.300 --> 02:08.060
And the parameter name is hurt.

02:08.060 --> 02:10.060
And make sure you spell it correct.

02:10.060 --> 02:12.580
And after that close that off with semicolon.

02:12.580 --> 02:16.660
And we're going to press down Ctrl s one more time in order to save our script.

02:16.660 --> 02:17.820
And now let's move over.

02:17.860 --> 02:19.180
Move over to unity.

02:19.470 --> 02:25.790
So as soon as, as soon as we're gonna start taking damage from this, uh, player game object, we

02:25.790 --> 02:30.470
will able to notice this enemy one gonna play the heart animation clip.

02:30.470 --> 02:37.350
And after playing that, it's gonna move over to idle or arrow fire, depending upon where player is.

02:37.350 --> 02:41.670
If the player is in attack range, then it's gonna shoot out the Ray.

02:42.030 --> 02:42.350
Sorry.

02:42.390 --> 02:45.430
It's gonna attack on this player game object.

02:45.870 --> 02:46.630
Our enemy.

02:46.670 --> 02:47.630
One game object.

02:47.630 --> 02:50.510
Just gonna damage our player game object.

02:50.510 --> 02:52.390
So let's have a look on this.

02:52.390 --> 02:56.750
So just wait a little moment, and once it's done, we're gonna able to see that.

02:58.270 --> 03:00.310
So just wait a little moment.

03:07.750 --> 03:09.750
So just wait a little moment.

03:09.750 --> 03:15.350
It's gonna take few second and after few second it's gonna be done.

03:15.350 --> 03:17.710
So now as you can see, it's done.

03:18.150 --> 03:25.590
And if we just go ahead and then click on this play button in the top in order to play our game.

03:25.590 --> 03:30.050
And then if we start, uh, Damaging our enemy one.

03:30.090 --> 03:33.730
Then this enemy one just gonna play the heart animation clip.

03:33.730 --> 03:39.930
And after that, it's gonna play the arrow, fire or idol, depending upon where player is.

03:40.210 --> 03:43.730
So let's get closer to this enemy one game object first.

03:43.730 --> 03:46.370
So I'm gonna get closer to this enemy one.

03:46.370 --> 03:51.610
And if I damage it, we can see this enemy one playing that damage animation clip.

03:51.610 --> 03:58.650
And once it's, uh, loses all of his health, then it just playing the diet, and after five seconds,

03:58.650 --> 04:00.770
it just get destroyed itself.

04:00.770 --> 04:06.930
So I'm gonna get out of play mode, and I'm gonna give some more health to this enemy one game object

04:06.930 --> 04:09.650
in order to check that heart animation clip.

04:09.650 --> 04:12.810
So I'm gonna select my enemy one GameObject in the hierarchy.

04:13.050 --> 04:16.690
Let's go over to Inspector, then enemy one script and the Maxhealth.

04:16.690 --> 04:21.210
I'm gonna make this one something around 50 in order to check it.

04:21.210 --> 04:23.090
You do not make it 50.

04:23.130 --> 04:28.090
You can make it less as much as you can for testing purposes.

04:28.130 --> 04:30.410
I'm just, uh, doing it with 50.

04:30.610 --> 04:32.130
So let's begin with this.

04:32.130 --> 04:34.930
So I'm gonna click on this start uh button.

04:35.130 --> 04:41.380
Sorry play button in the top so we can play our game and let's have a look on it.

04:41.820 --> 04:47.740
So as soon as we just gonna damage our enemy one, it's gonna play the heart animation clip.

04:47.900 --> 04:49.980
So let's do that first.

04:50.100 --> 04:53.940
Firstly, we need to get closer to this enemy one game object.

04:53.940 --> 04:55.300
So let's damage it.

04:55.300 --> 04:58.500
Now we can see it's playing the heart animation clip.

04:58.500 --> 05:02.380
And right after it it's playing the arrow fire.

05:02.420 --> 05:05.380
Because this player inside attack range.

05:05.380 --> 05:06.260
So that's why.

05:06.700 --> 05:07.580
And we can see.

05:07.620 --> 05:11.940
And after playing the heart animation clip it's playing the arrow fire.

05:11.980 --> 05:16.940
Because we are in you can simply say in attack range.

05:16.940 --> 05:23.820
And if we just go far away from this enemy one game object, then we can notice it's playing the idle

05:23.820 --> 05:26.660
animation clip over again and again.

05:26.660 --> 05:29.540
So I hope you get the idea that how you can do it.

05:29.540 --> 05:35.820
So we also need to do something in order to make this one cool, like camera shaking and as well as

05:35.860 --> 05:42.660
a floating text just gonna pop up once this animated enemy one game object takes damage.

05:42.660 --> 05:44.340
So I'm gonna get out of play mode.

05:44.340 --> 05:47.380
So I hope you get the idea that how you can do it.
