WEBVTT

00:00.080 --> 00:05.240
We will make the animation of this anime two game object first, and then we're gonna code it.

00:05.520 --> 00:07.720
We're going to control through C script.

00:07.760 --> 00:12.800
As you seen, we just printing out a message in the console says player in attack range.

00:12.960 --> 00:18.080
Instead of that this anime game object need to attack on our player game object.

00:18.080 --> 00:24.320
So let's make the animation first and then we're gonna control those through our C script.

00:24.320 --> 00:25.280
So let's do that.

00:25.280 --> 00:31.880
So I'm gonna move over to my project tab, then sprites basically where I have the skeleton sprite sheet.

00:31.880 --> 00:35.600
So in my skeleton folder as you can see.

00:35.600 --> 00:37.360
So I'm going to choose the ideal one.

00:37.360 --> 00:39.120
So let's click on this arrow.

00:39.120 --> 00:42.880
And let's select all of these individual sprite by holding down shift.

00:42.880 --> 00:46.720
And then drag it over to this anime two game object in the hierarchy.

00:46.720 --> 00:49.040
And it's gonna make the animation right away.

00:49.040 --> 00:52.840
So what we will do, we will move over to the assets folder in the top left.

00:52.840 --> 00:54.600
I'm going to click on this back arrow.

00:54.640 --> 00:55.960
Let's go to assets.

00:56.080 --> 01:00.720
And we do know in assets we created this animation folder as you can see.

01:00.720 --> 01:04.000
So we're gonna open that sub folder by double clicking on it.

01:04.000 --> 01:06.520
And also we have anime animation.

01:06.520 --> 01:11.320
And I'm gonna create a another sub folder for this anime two animation.

01:11.320 --> 01:14.560
So let's right click then new folder.

01:14.560 --> 01:22.040
And I'm going to call this folder to something like anime two underscore animation anime two underscore

01:22.040 --> 01:22.680
animation.

01:22.680 --> 01:23.920
Let's hit enter.

01:23.920 --> 01:27.520
And let's open this sub folder as well by double clicking on it.

01:27.520 --> 01:32.000
And we have to name the animation what we want to name it now.

01:32.160 --> 01:36.920
So I'm going to call it something like anime two underscore idle animation.

01:36.920 --> 01:42.160
So I'm going to call it anime two, anime two underscore idle.

01:43.000 --> 01:44.560
And let's click on this save.

01:44.800 --> 01:50.680
And now let's select the I'm going to drag my anime to game object in the top of my hierarchy so I can

01:50.680 --> 01:51.760
see all the time.

01:51.760 --> 01:53.600
And let's go to animation tab.

01:53.600 --> 02:00.080
And if we click on this play button now as you can see, our skeleton just playing the idle animation

02:00.080 --> 02:02.170
clip over again and again.

02:02.170 --> 02:05.810
So we also need to create the attack animation as well.

02:05.810 --> 02:06.570
So let's do that.

02:06.570 --> 02:10.770
So we're going to move over to project tab and let's choose the attack one.

02:10.970 --> 02:12.210
So we have it over here.

02:12.210 --> 02:13.610
Let's click on this arrow.

02:13.610 --> 02:18.090
And we're going to select all of these individual sprites by holding down shift.

02:18.090 --> 02:21.930
And let's drag it over to a animator GameObject in the hierarchy.

02:22.170 --> 02:28.650
Let's go to assets and then animation Enemy Animation and Animator Animation.

02:28.650 --> 02:34.210
And I'm going to call this animation clip to something like enemy to underscore attack because this

02:34.210 --> 02:35.410
is the attack one.

02:35.610 --> 02:38.650
And now let's click on this Save and move.

02:38.690 --> 02:44.290
If we move over to animation tab and then click over here and choose enemy to Underscore attack.

02:44.290 --> 02:45.890
And then click on this play button.

02:45.890 --> 02:51.850
We can see the attack animation just playing over again and again by now as you can see.

02:52.090 --> 02:54.250
So we have the animation by now.

02:54.250 --> 02:58.210
So we can create a attack animation clip as well.

02:58.250 --> 03:00.010
But I'm going to leave it for now.

03:00.250 --> 03:05.090
And if we select our animator GameObject in the hierarchy, move over to animator tab.

03:05.090 --> 03:07.170
We can see we have two animation clip.

03:07.170 --> 03:09.690
We have the idle one as well as attack.

03:09.690 --> 03:15.050
So if I just click on this play button in the top, you will see this idle animation will be played

03:15.050 --> 03:16.890
right after the game starts.

03:16.890 --> 03:23.610
So we also need to play this attack animation clip once our player GameObject in attack range.

03:23.610 --> 03:25.170
So just wait for it to compile.

03:25.210 --> 03:31.570
As you can see, enemy is now playing the idle animation clip over again and again, so it's also need

03:31.570 --> 03:33.530
to play this attack animation clip.

03:33.530 --> 03:37.970
So let's get out of play mode and let's make transition from this idle to attack.

03:37.970 --> 03:40.690
So in order to play the attack animation clip.

03:40.690 --> 03:43.490
So I'm going to right click Make Transition to Attack.

03:43.490 --> 03:47.290
And let's select this transition or this arrow over to Inspector.

03:47.290 --> 03:53.010
And we're going to untick this has exit time because as soon as this player game object in attack range,

03:53.050 --> 03:59.610
this enemy two game object need to play the attack to animation attack animation clip right away.

03:59.610 --> 04:05.300
So that's why we just untick the has exit time as well as we're gonna set the transition duration to

04:05.340 --> 04:05.780
zero.

04:05.780 --> 04:06.900
And let's scroll down.

04:06.900 --> 04:12.260
We need to choose a condition in which condition we want to play that animation clip.

04:12.260 --> 04:16.660
So we're going to choose some certain condition or parameter in order to do that.

04:16.660 --> 04:18.300
So let's go to animator tab.

04:18.300 --> 04:19.980
In the left side you can see layers.

04:20.020 --> 04:22.740
And in the right side we can see parameters.

04:22.740 --> 04:26.380
So let's click on this plus icon and then choose this bool parameter.

04:26.380 --> 04:30.180
And you can call this parameter to anything that you like.

04:30.180 --> 04:32.660
So I'm going to call it something like attack.

04:32.860 --> 04:34.660
And I want to choose this condition.

04:34.660 --> 04:36.380
So let's select the transition.

04:36.380 --> 04:37.500
Let's go to Inspector.

04:37.500 --> 04:42.100
Scroll down and we're going to click on this plus icon in order to choose the condition.

04:42.100 --> 04:44.380
So if attack parameter is true.

04:44.380 --> 04:49.980
So if we set this attack parameter to true basically check you will see this idle animation will be

04:49.980 --> 04:51.380
played right away.

04:51.420 --> 04:53.740
Sorry not not idle animation.

04:53.780 --> 04:55.980
Basically the attack animation clip.

04:56.020 --> 04:57.620
It's gonna play right away.

04:57.620 --> 05:01.260
And also we need to make transition from this attack to idle.

05:01.260 --> 05:06.460
Once our player game object is not in attack range of this enemy two game object.

05:06.460 --> 05:13.340
So we also need to back transition from this attack to idle, or we will stack forever into this attack

05:13.380 --> 05:14.260
animation clip.

05:14.260 --> 05:19.260
So let's right click on this attack animation clip and let's make transition back to idle.

05:19.420 --> 05:20.860
And let's select the transition.

05:20.860 --> 05:26.140
Go over to Inspector and we're going to untick this as exit has exit time as well as I'm going to set

05:26.140 --> 05:28.020
the transition duration to zero.

05:28.180 --> 05:29.580
And if we scroll down.

05:29.580 --> 05:35.100
So we need to choose a condition in which condition we want to play the idle animation clip.

05:35.100 --> 05:40.380
So I'm going to choose the same condition which is attack we recently created as you can see attack

05:40.380 --> 05:40.860
parameter.

05:40.860 --> 05:42.540
So we're going to choose that condition.

05:42.540 --> 05:44.300
So let's click on this plus icon.

05:44.300 --> 05:47.980
And now we're going to check if the attack is false.

05:47.980 --> 05:53.700
So if we set this attack parameter to false basically uncheck you will see this idle animation clip

05:53.740 --> 05:56.820
of this enemy game object will be played right away.

05:56.820 --> 05:57.780
So let's have a look.

05:57.820 --> 06:04.350
And we're going to set this attack parameter Manually and later on we can control this through our script.

06:04.350 --> 06:07.270
So let's click on this play button and let's have a look.

06:07.270 --> 06:13.150
So if we set this attack parameter to true manually basically check you will see this attack animation

06:13.150 --> 06:13.870
will be played.

06:13.870 --> 06:14.150
Why.

06:14.190 --> 06:17.910
Because we have chosen that condition from this idle to attack.

06:17.910 --> 06:24.150
So if I set this attack parameter to true, as you can see, as soon as we have set it to true, the

06:24.150 --> 06:29.630
attack animation is just playing over again and again in this enemy two game object.

06:29.630 --> 06:32.830
And if I set this attack parameter to false, basically uncheck.

06:32.830 --> 06:37.670
Now this enemy game object is playing the idle animation clip, as you can see.

06:37.830 --> 06:43.510
So what we basically need to do, we need to control this attack parameter through our script depending

06:43.550 --> 06:45.230
upon where player is.

06:45.230 --> 06:50.750
If the player is close enough to this enemy game object, then this enemy game object need to play the

06:50.750 --> 06:51.910
attack animation clip.

06:51.950 --> 06:54.790
Basically, we need to set this attack parameter to true.

06:55.150 --> 06:56.750
So let's get out of play mode.

06:56.790 --> 06:59.190
I hope you get the idea that how you can do.

06:59.230 --> 07:03.310
And now we need to control this attack parameter through our script.

07:03.390 --> 07:04.710
So let's do that.

07:04.710 --> 07:05.630
So we're going to do that.

07:05.630 --> 07:08.870
So let's select our animator GameObject in the hierarchy.

07:08.870 --> 07:11.670
And let's open up the animation to script right away.

07:12.190 --> 07:18.230
And as you can see uh, we when we created all of this animation clip, basically this attack, uh,

07:18.230 --> 07:25.110
enemy to idle and this attack enemy to attack, we can see an animator component just added right away.

07:25.110 --> 07:27.870
Once we created all of this animation clip.

07:28.030 --> 07:32.950
And this animator component is responsible for switching our animation.

07:32.950 --> 07:39.030
So what we basically need we need a reference of this animator component of this animator game object.

07:39.030 --> 07:40.790
Then we can set the parameter.

07:40.790 --> 07:43.470
So let's open up the animator script right away.

07:43.470 --> 07:47.950
And let's uh go to the top of our class and let's grab the reference first.

07:47.950 --> 07:49.350
So I'm going to make a public.

07:49.350 --> 07:52.030
And the component we're looking for is animator.

07:52.070 --> 07:57.590
So we're going to type animator sorry any mater.

07:57.870 --> 08:00.230
And we're going to call it something like animator.

08:00.230 --> 08:02.040
And let's close that up with semicolon.

08:02.040 --> 08:04.760
And we're going to press down Ctrl S to save our script.

08:04.760 --> 08:06.040
And let's move to unity.

08:07.360 --> 08:11.400
So underneath our enemy two script we will see that animator field.

08:11.400 --> 08:13.520
And by default it's going to be empty.

08:13.520 --> 08:18.840
So what we need to do right there we need to drag this animator component into that slot.

08:18.880 --> 08:21.040
So we're going to have this animator reference.

08:21.040 --> 08:24.840
Then we can just set this attack parameter through our script.

08:26.200 --> 08:29.760
So as you can see animator and it says animator.

08:29.760 --> 08:32.920
So we'll select our animator and drag it right there.

08:32.960 --> 08:39.560
Now we can see we have the animator anime to animator component reference, and we are ready to set

08:39.560 --> 08:41.720
this attack parameter through our code.

08:41.720 --> 08:45.480
So let's go to script and we're going to move over to this call info.

08:45.680 --> 08:51.160
As you can see we just printing out a message in the console says a player in attack range.

08:51.160 --> 08:56.880
So instead of printing out message what we want to do once our player GameObject get inside of this

08:56.880 --> 09:01.800
circle, then this enemy two GameObject need to play the attack animation clip.

09:01.840 --> 09:04.720
Basically, we need to set this attack parameter to true.

09:04.880 --> 09:05.880
To true true.

09:05.920 --> 09:09.000
Uh, to uh to true through our code.

09:09.120 --> 09:11.640
So we do know we have the animator reference.

09:11.640 --> 09:12.880
So let's do that.

09:12.880 --> 09:16.120
So what we will do, we will go over to animator component.

09:16.120 --> 09:18.880
And then we're going to use this dot set bool function.

09:18.880 --> 09:21.040
So why are we using this set bool function.

09:21.040 --> 09:26.800
Because this attack parameter we can see in the animator tab is a bool parameter.

09:26.800 --> 09:29.840
This attack we have chosen a bool parameter.

09:29.840 --> 09:33.640
So that's why we need to use this set bool function as a first argument.

09:33.640 --> 09:36.480
This set will in in quotation or in.

09:36.600 --> 09:40.680
It's going to take the string name or the parameter name in quotation.

09:40.680 --> 09:43.000
And the second thing it's going to take the value.

09:43.000 --> 09:45.920
So first thing it's going to take the parameter name.

09:45.920 --> 09:49.280
So make sure you just do inside this quotation.

09:49.280 --> 09:51.200
And the parameter name is attack.

09:51.200 --> 09:55.240
And the second thing comma it's gonna need the value.

09:55.240 --> 09:57.480
So we're gonna set it to true basically means check.

09:57.520 --> 10:00.360
And we do know once we set it to true means take.

10:00.400 --> 10:03.930
It's going to play the attack animation clip right away.

10:03.930 --> 10:06.970
So that's why as a second argument we're going to pass that true.

10:06.970 --> 10:08.850
And let's close that up with semicolon.

10:08.850 --> 10:14.370
So basically what we're doing we're just moving over to this animated anime to game object, this animator

10:14.370 --> 10:15.090
component.

10:15.090 --> 10:21.050
And then by this animator component which is setting this attack parameter, uh, this attack bool parameter

10:21.050 --> 10:24.690
to true, as you can see, uh, over here.

10:24.930 --> 10:31.770
And let's suppose if the player is not in, uh, inside of this attack range of this player, sorry,

10:31.810 --> 10:39.130
anime to game object means, uh, this player game object a little bit far away from this anime to game

10:39.170 --> 10:39.770
object.

10:39.770 --> 10:45.810
So in that moment, what this anime to game object need to do it need to play the idle animation clip

10:45.810 --> 10:51.810
instead of the attack, because our player game object is just gonna be far away from this anime to

10:51.850 --> 10:52.690
game object.

10:52.690 --> 10:57.010
So what we will do, we will go to script and we will check else, so else.

10:57.050 --> 11:04.860
The player is far from our this article is of this anime two game object, or this player game object

11:04.860 --> 11:09.060
is not collided to this anime two game object circle yet.

11:09.060 --> 11:13.100
So in that moment what we it's this anime two game object need to do.

11:13.140 --> 11:20.940
It's it's need to play the idle animation clip instead of the attack one where basically a player game

11:20.980 --> 11:22.700
object is little bit far away.

11:22.700 --> 11:31.100
So that's why so else our player is not attack range means our player game object is far from our anime

11:31.100 --> 11:31.900
game object.

11:31.900 --> 11:38.460
So in that moment our anime two game object need to play the idle animation clip instead of the attack

11:38.460 --> 11:38.900
one.

11:38.900 --> 11:43.460
So we're going to move over to animator, and we're going to use this set function one more time in

11:43.460 --> 11:49.180
order to set the pool as a first argument in quotation, it's going to take the parameter name.

11:49.180 --> 11:51.140
So in our case this attack.

11:51.140 --> 11:53.340
And the second thing it's going to take the value.

11:53.380 --> 11:56.020
So we're going to set it to false basically means unchecked.

11:56.020 --> 12:01.860
So we do know once we uncheck or set to false it's going to play the idle ideal animation clip instead

12:01.860 --> 12:02.940
of the attack one.

12:02.940 --> 12:06.020
Basically, we have chosen that condition as you've seen.

12:06.020 --> 12:07.900
So we're going to close that off with semicolon.

12:07.900 --> 12:11.500
And let's press down control S in order to save our script.

12:11.540 --> 12:13.300
Now let's move over to unity.

12:13.340 --> 12:16.860
You will see this, uh, this enemy two GameObject.

12:17.020 --> 12:24.340
Uh, just gonna play the idle animation clip once our player GameObject not inside of this attack range.

12:24.620 --> 12:27.580
Uh, attack enemy to a game object.

12:27.580 --> 12:28.460
So just wait.

12:28.580 --> 12:33.900
And now if we just click on this play, uh, play button in the top, you will see that.

12:40.500 --> 12:43.100
So let's get inside first.

12:45.660 --> 12:47.420
We jumped a lot.

12:47.940 --> 12:54.220
So let's as you can see now enemy just uh, playing the attack animation clip over again and again.

12:54.220 --> 13:00.220
And once we go outside of this attack radius or attack range of this enemy two game object, we can

13:00.220 --> 13:06.700
see anime to game object is now playing the idle animation clip over again and again, so we can take

13:06.700 --> 13:10.100
a look in animator tab as well as you can see.

13:10.100 --> 13:11.660
So we're going to get out of play mode.

13:11.660 --> 13:17.020
I hope you get the idea that how you can just do that and we're going to move over to this overrides

13:17.020 --> 13:20.220
and then click on Apply All in this animator game object.

13:20.220 --> 13:25.860
So the change is over here we made it's going to be saved into this anime two game object prefab as

13:25.860 --> 13:26.220
well.

13:26.380 --> 13:29.700
And I want to move this animator component to the up.

13:29.700 --> 13:32.420
And I want this anime to script in the bottom.

13:32.420 --> 13:33.820
So how we can do that?

13:33.860 --> 13:40.620
In order to do that, we need to open up this or in prefab mode so we can see in the right section open.

13:40.620 --> 13:44.420
So let's click there and we're going to right click on this animator component.

13:44.420 --> 13:47.620
And we're going to click on this move up in order to move it up.

13:47.620 --> 13:51.700
And now this anime two game object is now in the town.

13:51.900 --> 13:57.620
And we can go back by clicking over here in hierarchy and into our scene view.

13:57.740 --> 14:01.420
And we're going to press down Ctrl S in order to save our project.
