WEBVTT

00:00.080 --> 00:04.960
Let's make transition between animation state of this anime game object.

00:04.960 --> 00:08.040
So we're going to select our anime one GameObject in the hierarchy.

00:08.040 --> 00:10.920
And let's move over to this animator tab.

00:10.920 --> 00:14.200
So we need to make transition to this shooting as well.

00:14.520 --> 00:16.160
So we're going to do that.

00:16.400 --> 00:20.080
Uh so let's right click on this idle make transition to shooting.

00:20.080 --> 00:21.600
And let's select this transition.

00:21.600 --> 00:22.800
Go to Inspector.

00:22.800 --> 00:25.240
And we're going to untick this as exit time.

00:25.240 --> 00:31.400
Because as soon as this player game object inside of that attack range, this anime game object need

00:31.440 --> 00:35.000
to play this animation clip right away.

00:35.160 --> 00:39.720
So that's why we untick and we're gonna set the transition duration to zero.

00:39.800 --> 00:40.640
Scroll down.

00:40.640 --> 00:43.480
We need to choose a condition in which condition?

00:43.480 --> 00:48.720
We just want to play that shooting animation clip of this anime game object.

00:48.720 --> 00:50.560
So I'm going to choose a condition.

00:50.560 --> 00:53.040
So let's go to Animator Parameters.

00:53.040 --> 00:54.960
So let's click on this plus icon.

00:54.960 --> 00:58.840
And we're going to choose a bool parameter which can be true or false.

00:58.840 --> 01:01.240
And we're going to call this something like attack.

01:01.280 --> 01:05.280
So I'm going to choose this condition if this attack parameter is true.

01:05.280 --> 01:08.000
So we're going to click on this plus icon in the inspector.

01:08.000 --> 01:12.080
And we're going to check if attack is true then it's going to play.

01:12.120 --> 01:15.280
Or we're going to play this shooting animation clip right away.

01:15.280 --> 01:18.680
Because as you can see we have chosen that condition.

01:18.680 --> 01:21.120
So I'm going to click on this play button in the top.

01:21.120 --> 01:23.960
And I'm going to set this attack parameter manually.

01:23.960 --> 01:25.360
Check basically means true.

01:25.560 --> 01:29.600
And as soon as we're going to set it it's going to play the shooting animation clip.

01:29.600 --> 01:30.000
Why?

01:30.040 --> 01:33.760
Because we have chosen that condition, as you can see in the inspector.

01:33.760 --> 01:37.000
So I'm going to check this manually basically shooting up.

01:37.400 --> 01:42.920
Plus basically you can simply say we're just setting it manually.

01:43.160 --> 01:50.040
And if I set this attack parameter to uncheck basically false, we can see we're not moving over to

01:50.320 --> 01:52.840
at all our idle animation clip.

01:53.120 --> 01:59.120
So what we need to do we need to play the idle animation clip one more time depending upon where the

01:59.120 --> 01:59.960
player is.

01:59.960 --> 02:03.640
If the player is far from attack range, Then it should.

02:04.560 --> 02:11.320
Then this player game enemy game object need to stop playing that shooting animation clip right away.

02:11.440 --> 02:15.440
So let's get out of play mode and we're going to make transition back to this idle.

02:15.440 --> 02:17.120
So let's right click on this shooting.

02:17.120 --> 02:19.760
And we're going to make to back to this idle.

02:19.760 --> 02:21.520
And let's select this transition.

02:21.760 --> 02:27.360
And we're gonna untick this as it has exit time as well as I'm going to set the transition duration

02:27.360 --> 02:28.000
to zero.

02:28.320 --> 02:33.000
And we're going to set this condition to false.

02:33.000 --> 02:34.920
So let's set this to false.

02:34.920 --> 02:41.200
Basically we have chosen if the attack parameter is false it's going to play this idle animation clip

02:41.200 --> 02:42.200
one more time.

02:42.520 --> 02:46.480
So what we need we need a reference of this animator component.

02:46.480 --> 02:52.880
So if I select my enemy game one GameObject in the hierarchy hierarchy and go over to Inspector, we

02:52.880 --> 02:59.920
can see a animator component is attached to this enemy one game object and this one is responsible for

02:59.960 --> 03:01.920
playing our animation clip.

03:01.920 --> 03:02.680
So what we need?

03:02.720 --> 03:05.680
We need a reference of this animator component.

03:05.720 --> 03:13.000
Then we can set this attack parameter to true or false, depending upon where player is a player is.

03:13.040 --> 03:17.160
So basically we need to get a reference of this animator component.

03:17.160 --> 03:20.920
Then we can set this attack parameter through our code.

03:20.960 --> 03:24.360
So let's grab the reference first of this animator component.

03:24.360 --> 03:26.480
So we're going to open up our anime script.

03:26.760 --> 03:29.880
And let's go to the top of our class.

03:29.880 --> 03:31.640
And we're going to make a public.

03:31.680 --> 03:34.240
And the component we're looking for is animator.

03:34.240 --> 03:36.400
So we're going to type animator.

03:36.680 --> 03:38.520
And we have to name name it.

03:38.520 --> 03:40.760
So I'm going to call it something like animator.

03:40.760 --> 03:43.040
And let's close that up with semicolon.

03:43.040 --> 03:45.880
And we're going to press down Ctrl S to save our script.

03:45.880 --> 03:47.960
And now let's move over to unity.

03:52.600 --> 03:58.160
So underneath our anime script we're going to able to see that animator parameter.

03:58.320 --> 04:02.160
So we need to drag this animator component into that slot.

04:02.200 --> 04:03.800
So we're going to have the reference.

04:03.800 --> 04:09.920
And then we can set this parameter to true or false depending upon where player is.

04:10.480 --> 04:16.520
So as soon as script gets compiled we can see animator and it says none animator basically empty.

04:16.560 --> 04:19.160
So we're going to take our animator and drag it there.

04:19.200 --> 04:19.760
There.

04:19.800 --> 04:24.480
Now we can see we have one anime, one animator component reference.

04:24.480 --> 04:26.560
And now we are ready to set.

04:26.600 --> 04:28.400
So let's double click that.

04:28.400 --> 04:35.560
And over here as you can see if call info is equals equals to true basically means this player game

04:35.560 --> 04:42.560
also gets inside of this attack range of this attack range enemy game object attack range.

04:42.680 --> 04:43.640
So what are we doing?

04:43.640 --> 04:46.240
We just printing out a message in the console.

04:46.360 --> 04:48.720
Console says attack on player.

04:48.720 --> 04:52.720
Instead of printing out message, we need to play that animation clip.

04:52.840 --> 04:57.560
So we will go to animator and we're going to use this set bool function.

04:57.840 --> 04:59.760
Set bool and make first bracket.

04:59.800 --> 05:01.920
Why are we using this set bool function.

05:01.920 --> 05:06.400
Because if we move to unity this attack parameter is a bool parameter.

05:06.400 --> 05:09.200
So that's why we need to use this set bool function.

05:09.200 --> 05:12.840
Firstly we moving over to animator, basically this animator.

05:12.840 --> 05:18.440
And then we using that self bool function in order to set this parameter as first argument.

05:18.440 --> 05:24.200
This set bool function, it's going to take the parameter in quotation the name of the parameter.

05:24.200 --> 05:28.520
So make sure you type quotation and you need to spell it correct, which is attack.

05:28.520 --> 05:31.680
We do know, so make sure you just go to unity and check it.

05:31.680 --> 05:35.680
And the second thing comma it's going to take the value that you want to set.

05:35.680 --> 05:37.800
So we're going to set it to true means checked.

05:37.800 --> 05:43.560
So once the player get in attack range then we need to play the attack animation means we need to set

05:43.560 --> 05:46.200
this attack parameter to true means state.

05:46.200 --> 05:47.560
So when set to true.

05:47.560 --> 05:49.800
And let's close that up with semicolon.

05:49.800 --> 05:51.960
But let's suppose this player game object.

05:51.960 --> 05:55.640
It's not in attack range of this enemy game object.

05:56.040 --> 06:00.520
Let's suppose this player game object a little bit far away from this enemy game object.

06:00.520 --> 06:06.850
In that moment, this enemy game object need to play the idle animation clip instead of the shooting

06:06.890 --> 06:07.890
animation clip.

06:07.890 --> 06:09.930
So that's why we're going to check.

06:09.970 --> 06:13.370
Else a else and then make some curly brackets.

06:13.370 --> 06:21.930
So else our enemy is our player is not in attack range means call info is true in that moment that enemy

06:21.930 --> 06:26.090
game object need to play the idle animation clip instead of the attack.

06:26.130 --> 06:27.890
So I'm going to move over to animator.

06:27.890 --> 06:30.650
We're going to use this set function in order to set.

06:30.690 --> 06:32.090
Let's make first bracket.

06:32.090 --> 06:34.730
And in quotation we're going to pass our parameter.

06:34.730 --> 06:37.170
And the second thing we need to set the value.

06:37.170 --> 06:41.370
So we're going to set equal set false uh basically unchecked.

06:41.370 --> 06:45.090
And we're going to press down control S in order to save our script.

06:45.090 --> 06:47.290
And now let's move over to unity.

06:47.490 --> 06:54.210
So as soon as this player GameObject gonna get inside of this enemy one game object, uh, attack range,

06:54.210 --> 06:56.290
you will see this enemy game object.

06:56.290 --> 07:03.250
Just gonna play the shooting animation clip right after this, uh, player game object gets inside of

07:03.290 --> 07:04.490
that attack range.

07:04.490 --> 07:05.770
So let me show you.

07:05.810 --> 07:10.570
Firstly, I'm going to select my player GameObject in the hierarchy, and I'm going to drag it a little

07:10.570 --> 07:15.490
bit further away from this enemy GameObject somewhere over here.

07:15.690 --> 07:21.850
And now if I just click on this play button, as soon as this player GameObject gonna get inside of

07:21.890 --> 07:29.290
that attack range enemy GameObject, then this enemy GameObject will play the attack animation or the

07:29.290 --> 07:30.450
shooting right away.

07:32.170 --> 07:39.370
So as you can see, it just normally playing the idle animation clip, and as soon as player GameObject

07:39.370 --> 07:41.330
gets inside of this attack range.

07:41.370 --> 07:42.810
As you can see, it's playing.

07:42.810 --> 07:45.050
Now the shooting animation clip.

07:45.090 --> 07:51.930
And if we just, uh, passes through this enemy GameObject, now we can see this enemy GameObject just

07:51.930 --> 07:55.770
playing the idle animation clip instead of the shooting one.

07:55.810 --> 07:56.130
Why?

07:56.170 --> 07:58.050
Because this player game object.

07:58.050 --> 08:02.970
As you can see, it's not inside attack range of this enemy GameObject.

08:02.970 --> 08:04.530
So basically that is the thing.

08:04.530 --> 08:06.210
And let's get out of play mode.

08:06.410 --> 08:10.810
And now what we have to do this enemy game object need to shoot a bullet.

08:10.930 --> 08:17.410
So if I select my enemy one game object in the hierarchy, go over to the animation tab and then click

08:17.410 --> 08:18.090
over here.

08:18.090 --> 08:23.890
In order to choose the shoot animation, we want to shoot a shoot something over here.

08:23.890 --> 08:28.930
So this is going to be a perfect time in order to shoot on this player game object.

08:28.930 --> 08:32.090
So what we're going to do we're going to make a shooting function.

08:32.090 --> 08:36.410
And then in that shooting function we're just going to spawn our bullet.

08:36.410 --> 08:38.970
For now let's create that.

08:38.970 --> 08:40.370
So let's go to script.

08:40.410 --> 08:43.210
And we're going to do it somewhere over here.

08:43.210 --> 08:45.850
And make sure you just making this function public.

08:45.850 --> 08:51.210
Because we're going to call this function over here in animation tab over something over here.

08:51.770 --> 08:53.170
So that is the reason.

08:53.970 --> 08:55.810
And for function we're going to type void.

08:55.810 --> 08:58.770
And we have to name the function what we want to name it.

08:58.770 --> 09:03.650
So I'm going to call it something like shoot and make first bracket and some curly brackets.

09:04.290 --> 09:09.090
For now we're going to print out a message and later on we're going to spawn our bullet.

09:09.090 --> 09:12.930
So we're going to type debug dot log in order to print out a message.

09:12.930 --> 09:15.810
And we're going to print out something like a shoot.

09:16.570 --> 09:17.050
Shoot.

09:17.090 --> 09:19.050
Let's close that up with semicolon.

09:19.050 --> 09:22.570
And let's press down Ctrl S in order to save our script.

09:22.570 --> 09:23.930
And let's move to unity.

09:24.210 --> 09:27.090
So we need to call the function we just made the function.

09:27.090 --> 09:28.970
We also need to call the function.

09:28.970 --> 09:33.250
But where we're going to call it we're going to call it through animation event.

09:33.650 --> 09:40.050
So if I select my anime anime one game object in the hierarchy, go to animation tab and then click

09:40.050 --> 09:42.490
over here in order to choose the animation.

09:42.690 --> 09:44.930
And we're going to call the function over here.

09:44.930 --> 09:47.970
So this is going to be perfect time as you can see.

09:47.970 --> 09:53.170
So we're going to click on this Add event in animation tab in the left bar over here.

09:53.170 --> 09:55.450
Basically you're going to get it select that.

09:55.450 --> 09:58.810
Go over to Inspector and it says no function selected.

09:58.810 --> 10:03.170
So let's click there and let's go to anime script methods basically function.

10:03.170 --> 10:05.130
And we're going to choose the shoot function.

10:05.170 --> 10:11.250
Basically we just going over to this anime script And then we just are calling this function.

10:11.250 --> 10:16.090
As you can see, we created over here, which is the uh function.

10:16.410 --> 10:19.010
And now and we're just calling it over here.

10:19.130 --> 10:20.850
So and what should function is doing.

10:20.850 --> 10:23.330
We're just printing out a message in the console.

10:23.370 --> 10:25.250
So as you can see.

10:25.610 --> 10:26.970
And let's go to unity.

10:27.010 --> 10:29.130
And I'm going to select my console tab.

10:29.130 --> 10:33.210
And let's click on this play button in the top in order to play our game.

10:33.530 --> 10:40.010
And as soon as this play enemy game object uh gonna play attack animation clip, you will see that message

10:40.010 --> 10:40.650
in the console.

10:40.650 --> 10:46.410
Just gonna pop up says shoot because we're calling the function through our in animation event.

10:47.010 --> 10:51.650
So just wait as soon as this player game object just gonna get inside.

10:51.690 --> 10:57.530
As you can see, as soon as get it's just playing the attack animation, this enemy game object and

10:57.530 --> 11:00.530
the short message just getting pop up every single time.

11:00.530 --> 11:06.570
This enemy game object playing the short animation clip because we calling the function inside through

11:06.810 --> 11:09.010
uh, inside through animation event.

11:09.010 --> 11:10.730
So I'm going to get out of play mode.
