WEBVTT

00:00.040 --> 00:05.080
Let's open up our anime to script in order to move this anime to game object.

00:05.320 --> 00:07.560
Uh, so so let's do that.

00:07.560 --> 00:15.280
So we will open up our anime script and let's go to top of our class and let's declare some variable.

00:15.280 --> 00:19.040
So we need the speed with how much speed we want to move.

00:19.040 --> 00:20.440
So let's do that.

00:20.440 --> 00:22.840
So firstly I'm going to give it a title.

00:23.440 --> 00:24.880
So just wait.

00:24.960 --> 00:28.040
It's lagging a little bit I really apologize for it.

00:28.440 --> 00:29.840
So just wait a moment.

00:32.400 --> 00:34.600
Uh let's now it's done.

00:34.600 --> 00:36.720
So let's go to top of our class.

00:36.720 --> 00:37.960
Let's give it a header.

00:38.440 --> 00:42.320
So header basically we just firstly we need to make square brackets.

00:42.520 --> 00:48.240
And then we have to type this header header and make this first bracket.

00:48.240 --> 00:50.920
And in quotation we can give the title.

00:50.920 --> 00:54.800
So let's say something like movement like that.

00:54.840 --> 00:58.440
Let's create a serialized field uh private.

00:58.840 --> 01:00.360
And this will be speed.

01:00.360 --> 01:02.570
So this will be a float parameter.

01:02.570 --> 01:04.570
And we can call this one something like.

01:04.610 --> 01:05.490
Move spit.

01:05.490 --> 01:08.890
Or let's simply call it work spit work spit.

01:08.890 --> 01:09.970
Something like that.

01:10.170 --> 01:16.290
And by default I'm going to give a default value something around uh, two f or two unit.

01:16.530 --> 01:20.050
And now what we will do we will move over to this update function.

01:20.210 --> 01:23.050
So this update function runs every single frame.

01:23.050 --> 01:26.370
So every single frame we need to move our enemy.

01:26.370 --> 01:30.090
So I want to move this enemy to GameObject to the left direction.

01:30.250 --> 01:37.770
And in order to move that what we have to do we basically need to use this transform dot translate function

01:37.810 --> 01:41.290
transform dot translate and then make this first bracket.

01:41.290 --> 01:42.890
So transform basically what.

01:42.930 --> 01:49.290
Basically this means we're just going over to this transform component of this enemy two GameObject.

01:49.290 --> 01:52.890
And we're using this translate function in order to move.

01:53.050 --> 01:58.930
And this translate function in brackets is going to take the direction in which direction you want to

01:58.970 --> 01:59.450
move.

01:59.450 --> 02:06.550
So since we want to move to the left direction so we can simply put a vector two dot left vector two

02:06.710 --> 02:14.830
dot left vector two dot left basically means -one inch the x and zero in the y, because we don't want

02:14.830 --> 02:19.190
to move this enemy to GameObject at all in the y direction.

02:19.190 --> 02:25.150
So and we want to move this enemy to GameObject to the left direction in the x axis.

02:25.150 --> 02:29.430
So that's why we put vector two dot vector two dot left.

02:29.470 --> 02:31.830
It's basically means -one inch the x.

02:31.830 --> 02:36.590
So it will be negative direction and one and zero in the y.

02:36.830 --> 02:43.430
And what we will do, we will multiply this with our time delta time to make frame rate constant because

02:43.430 --> 02:45.430
we are doing inside this update function.

02:45.430 --> 02:50.390
So we need to make our speed constant every single frame.

02:50.390 --> 02:53.550
So that's why we're going to multiply with time dot delta time.

02:53.550 --> 02:55.710
And let's close that up with semicolon.

02:55.710 --> 02:59.150
And we also want to multiply these things with our speed.

02:59.150 --> 03:06.160
So we can just move a little bit faster, or with how much speed we just want to move our enemy to game

03:06.200 --> 03:06.800
object.

03:06.800 --> 03:10.120
So let's multiply this whole thing with our workspace.

03:10.320 --> 03:13.280
And now we're going to press down Ctrl S to save our script.

03:13.280 --> 03:15.120
And now let's move over to unity.

03:15.320 --> 03:22.320
And you will see as soon as are we gonna start our game, this enemy, we're just gonna start moving

03:22.360 --> 03:25.040
to the left direction for this enemy to.

03:25.080 --> 03:27.920
I'm just gonna create an another ground.

03:27.920 --> 03:32.320
Simply, I'm gonna duplicate this ground GameObject from the hierarchy tab.

03:32.640 --> 03:37.000
And that ground, I want to check with this enemy to game object.

03:37.000 --> 03:40.360
So that's why uh, so we're going to do that.

03:40.360 --> 03:46.080
Or we can just simply, uh, we can do it, uh, in this ground as well.

03:46.080 --> 03:50.000
So I'm going to make the jump height of this player game object a little bit up.

03:50.040 --> 03:57.440
I'm gonna bump up the jump height of this player game object in order to jump, jump over top of this

03:57.440 --> 04:02.660
enemy game object so we can easily pass through it, and it's taking a longer time.

04:02.660 --> 04:04.060
Now it's fine.

04:04.460 --> 04:08.660
And as soon as our anime script just gets compiled, sorry.

04:09.100 --> 04:15.980
If I move over to unity, we can see underneath our anime script, we can see the title, which is movement,

04:15.980 --> 04:17.820
and we can see the work speed.

04:17.820 --> 04:19.420
By default we set it to two.

04:19.660 --> 04:25.460
And now what we're gonna do, uh, I'm going to make the jump height a little bit up, and I'm going

04:25.500 --> 04:28.220
to bump up the jump height of this player game object.

04:28.220 --> 04:32.380
So I will select simply select my player game object in a hierarchy.

04:32.660 --> 04:38.620
Let's go over to Inspector then player skip and a jump height over here I'm going to make it something

04:38.620 --> 04:39.980
like 25.

04:40.420 --> 04:42.740
So now that's uh that's great.

04:42.740 --> 04:48.100
And if I just go ahead and then click on this play button, you will see this, uh, anime two game

04:48.140 --> 04:48.500
object.

04:48.500 --> 04:52.580
Just gonna move as soon as the game just gonna start.

04:52.580 --> 04:59.060
It will start moving to the left direction with work speed that we created, uh, the work speed.

04:59.060 --> 05:05.750
And we can see indeed this animated GameObject just moving to the left side, uh, with our work speed.

05:05.750 --> 05:07.910
But it's get fall down over here.

05:08.070 --> 05:15.510
So once the enemy something over here at the end of our round, then we need to flip this enemy to the

05:15.510 --> 05:16.510
right direction.

05:16.790 --> 05:20.190
But before we do, we're gonna do a little bit one thing.

05:20.190 --> 05:22.270
So we're gonna get out of play mode.

05:22.310 --> 05:29.230
What we basically want to do, uh, we want to create a circle around this enemy to game object, uh,

05:29.630 --> 05:30.790
enemy to game object.

05:30.790 --> 05:37.470
And if this, uh, if this, uh, player game object, just get inside of this enemy game object attack

05:37.470 --> 05:41.390
range or in that circle, then we're gonna attack on this.

05:41.630 --> 05:43.950
Uh, we're gonna play the attack animation clip.

05:43.950 --> 05:48.470
Basically, we're gonna do the same thing as we have done with enemy one game object.

05:48.750 --> 05:52.590
Uh, I guess, but before we do, let's do the flip thing.

05:52.870 --> 05:54.350
Uh, so let's do it.

05:54.350 --> 05:57.310
So we will move over to our enemy two script.

05:57.310 --> 06:02.840
Basically, we will open up our animated script by double clicking on it, and let's go to top of our

06:02.840 --> 06:05.480
class and let's declare some variable.

06:05.480 --> 06:07.040
So we're going to shoot out a ray.

06:07.600 --> 06:13.480
Shoot out a ray from somewhere over here in front of this enemy two game object.

06:13.480 --> 06:16.840
And if that ray don't collide with this ground game object.

06:16.840 --> 06:20.280
So something over here, it's not gonna collide at all.

06:20.280 --> 06:24.720
So in that moment, what we're gonna do, we're gonna flip this enemy to the right direction.

06:24.920 --> 06:29.320
And in order to create the ray, we need to use a function called raycast.

06:29.480 --> 06:29.840
So.

06:30.280 --> 06:36.000
But before we do, let's create a variable in order to keep track of which direction this enemy two

06:36.040 --> 06:37.840
is are facing.

06:38.040 --> 06:41.400
So as we can notice, it's facing to the left direction.

06:41.400 --> 06:47.280
So we're going to create a private bool parameter to just keep track of which direction this enemy is

06:47.280 --> 06:47.960
looking.

06:47.960 --> 06:51.320
So let's go to our script and let's make a private.

06:52.320 --> 06:54.760
This will be bool which can be true or false.

06:54.760 --> 06:57.200
And we can call this one facing left.

06:57.240 --> 06:59.900
Sorry, we need to do it over here.

06:59.900 --> 07:03.100
So let's call this one facing left.

07:03.260 --> 07:05.740
And let's close that up with semicolon.

07:05.740 --> 07:08.460
And now I'm going to move over to this start function.

07:08.460 --> 07:12.940
So in the start of the game I'm going to set my facing left equal to true.

07:13.220 --> 07:14.300
Equal to true.

07:14.300 --> 07:16.780
And let's close that up with semicolon y.

07:16.780 --> 07:18.700
We set it to true in this start of the game.

07:18.700 --> 07:24.500
Because in the start of the game this enemy as you can see it's looking to the left direction.

07:24.500 --> 07:31.220
So that's why in the start of the game I just set, I just said that facing left parameter to true as

07:31.220 --> 07:32.140
you can notice.

07:32.140 --> 07:35.740
And now what we have to do, we need to create a shoot out the ray.

07:35.940 --> 07:41.220
And in order to shoot out the ray we need to use a function called physics 2D raycast.

07:41.340 --> 07:44.420
So let's do that and we're going to do it update function.

07:44.420 --> 07:46.380
Or we can make a function for it.

07:46.380 --> 07:48.300
But let's do it over here.

07:48.300 --> 07:51.900
Instead of creating a separate function for this.

07:52.980 --> 08:00.870
And to to shoot out the ray we need to use this physics 2D dot raycast function and this raycast function

08:00.870 --> 08:01.990
as a first argument.

08:01.990 --> 08:05.550
It's going to take the position from where you want to shoot out the ray.

08:05.590 --> 08:10.990
So we're going to create a point, basically an empty shell game object of this animator game object

08:10.990 --> 08:12.390
somewhere around here.

08:12.510 --> 08:15.070
And from that frame, we're gonna shoot out the ray.

08:15.350 --> 08:16.230
Shoot out the ray.

08:16.910 --> 08:19.670
So we need we need to create that point.

08:19.670 --> 08:21.550
And the second thing it's going to take.

08:21.550 --> 08:24.710
So if we just move over, it's going to take the direction.

08:24.710 --> 08:27.550
So we're going to shoot out in the down direction.

08:27.790 --> 08:31.750
And the third argument it's going to take the distance basically length of the ray.

08:31.750 --> 08:34.510
So we need to specify that as well.

08:34.710 --> 08:40.350
And the third and the fourth argument it's going to take the layer mask basically with which game object

08:40.350 --> 08:42.550
we want we want to check with.

08:42.590 --> 08:44.150
So we're going to check with this ground.

08:44.190 --> 08:46.830
So as a layer mask we're going to choose this ground.

08:46.910 --> 08:49.950
So we need those variable before we shoot out the ray.

08:49.950 --> 08:52.950
So let's make this one comment by double forward slash.

08:52.990 --> 08:55.030
And let's go to top of our class.

08:55.030 --> 08:58.680
And let's uh let's assign those variable first.

08:58.760 --> 09:01.360
So before we do let's give it a title.

09:01.360 --> 09:03.000
So let's create this header.

09:03.240 --> 09:06.680
And we can call this one something like ground detection.

09:06.680 --> 09:08.760
So let's call ground detection.

09:08.800 --> 09:11.600
The title we're giving is ground detection.

09:12.160 --> 09:18.880
Uh detection I really apologize if the spelling is wrong I think it's, uh fine.

09:18.880 --> 09:20.360
So now what we have to do.

09:20.360 --> 09:21.880
We need to grab the reference.

09:21.880 --> 09:24.080
So first thing we need our position.

09:24.080 --> 09:27.280
So let's create a serialized field private.

09:27.560 --> 09:34.240
And for position we need to try this transform which is responsible for position rotation and scale.

09:34.440 --> 09:39.080
And we can call this one something like ground point or check point.

09:39.400 --> 09:42.400
Uh so let's call shootout ground check point.

09:42.400 --> 09:48.280
So let's call it ground ground check point check point.

09:48.280 --> 09:51.640
Or we can simply call it check point as well.

09:51.640 --> 09:54.400
So let's call it instead ground Check Point.

09:54.400 --> 09:57.860
So I'm going to call this one Crown Shake.

09:57.900 --> 09:58.620
Point.

09:59.820 --> 10:00.300
Point.

10:00.300 --> 10:03.340
And the second thing it's going to take the direction.

10:03.340 --> 10:05.620
So we don't need to create that parameter.

10:05.620 --> 10:07.260
Since we're going to use vector two.

10:07.260 --> 10:13.980
Dot down basically means uh one in the uh sorry y in the y minus one.

10:13.980 --> 10:17.020
So it's going to be negative and zero in the x.

10:17.020 --> 10:21.260
So means basically means that it's just going to shoot out in the down direction.

10:21.260 --> 10:23.460
So we don't need to specify that.

10:23.660 --> 10:28.020
So we will uh so we can just move over to our third argument.

10:28.020 --> 10:31.820
So we need to specify the length of the array or distance.

10:31.820 --> 10:35.020
So let's create another serialized field private.

10:35.020 --> 10:36.580
And this will be float.

10:36.580 --> 10:38.740
And we can call this one array length.

10:38.940 --> 10:41.580
Or let's call it distance instead.

10:41.820 --> 10:43.660
So let's call this one distance.

10:43.660 --> 10:49.380
And by default I'm going to set it to something like zero point 5FA little bit less number.

10:49.620 --> 10:52.500
Or we can just go with 0.3 as well.

10:52.860 --> 10:54.020
Something like that.

10:54.020 --> 10:56.740
And the fourth argument we need the layer mask.

10:56.740 --> 11:01.190
So let's create another serialized field private, private.

11:01.190 --> 11:02.990
And this will be Layer Mask.

11:02.990 --> 11:08.670
And we can call this something like target layer or let's call it what is Crown.

11:09.030 --> 11:10.430
What is crown.

11:10.470 --> 11:12.670
And now let's close that off with semicolon.

11:12.950 --> 11:15.950
And let's press down Ctrl S to save our script.

11:15.950 --> 11:17.630
And let's head over to unity.

11:18.070 --> 11:21.550
So we need to assign those variable by one by one.

11:21.550 --> 11:24.910
So the first thing just gonna pop up our ground checkpoint.

11:24.910 --> 11:31.950
So we will create an empty game object or an empty game object inside this animator game object.

11:32.150 --> 11:38.470
And we're going to make that one child, uh, since, uh, we want to shoot out the ray from that point.

11:38.470 --> 11:43.390
So we're gonna create an empty child game object inside this anime game object.

11:43.750 --> 11:49.670
So as you can see, as soon as our animator script just gets compiled, we can see ground detection

11:49.670 --> 11:54.590
title, and we have the ground checkpoint as well as the distance and what is ground.

11:54.590 --> 11:55.710
So we have this.

11:55.710 --> 11:57.450
So let's create the point first.

11:57.450 --> 12:00.370
So I'm going to select my enemy two GameObject in the hierarchy.

12:00.530 --> 12:01.890
Let's right click on it.

12:01.930 --> 12:04.810
Let's create an empty empty game object.

12:04.810 --> 12:10.490
And we can call this GameObject something like Round Checkpoint as we name it the variable earlier.

12:10.490 --> 12:15.010
So I'm going to call it Ground Checkpoint and make sure you go to Inspector.

12:15.050 --> 12:16.050
Then click here.

12:16.170 --> 12:18.690
Click here if you want to choose an icon.

12:18.690 --> 12:22.010
So let's choose this yellow one, something like that.

12:22.010 --> 12:24.490
And let's select this move tool from the scene view.

12:24.490 --> 12:30.890
And let's move it in front of this you can simply say in front of this enemy two GameObject somewhere

12:31.130 --> 12:32.410
over here.

12:32.410 --> 12:35.050
So from this point we want to shoot out the ray.

12:35.050 --> 12:36.650
So that's why we created.

12:36.650 --> 12:40.050
So now we will select our enemy two GameObject in the hierarchy.

12:40.250 --> 12:45.490
And let's select this ground checkpoint and drag it over to this ground checkpoint field.

12:45.530 --> 12:48.850
Now we have the ground checkpoint or basically this position.

12:48.850 --> 12:51.450
And we are ready to shoot out the ray.

12:51.690 --> 12:52.650
And what is ground?

12:52.650 --> 12:56.090
We're going to choose our ground since we want to check with this ground.

12:56.090 --> 12:59.780
But before you choose your crown, make sure you select your crown.

12:59.780 --> 13:02.140
Then go over to Inspector and Layer.

13:02.140 --> 13:08.340
You can see it will be default, so just click on click on add layer, name the layer, whatever you

13:08.340 --> 13:08.740
want.

13:08.780 --> 13:13.900
So call it something like Crown and after that make sure you select that game object one more time.

13:13.900 --> 13:22.020
So in our case Crown and go over to Inspector and Assign with the layer that you recently created.

13:22.020 --> 13:26.500
So as you can notice, I assigned this ground as a ground layer.

13:26.500 --> 13:28.420
We can notice in Inspector.

13:28.420 --> 13:31.460
So I will head over to my animator game object.

13:31.460 --> 13:37.180
And what is ground I'm gonna choose this ground says since the ray I want to check with this ground

13:37.220 --> 13:37.980
game object.

13:38.300 --> 13:41.820
And also we need to move over to this overrides in inspector.

13:41.860 --> 13:42.900
Then apply all.

13:42.900 --> 13:48.220
So the changes we made, it's going to be saved into this animator GameObject prefab as well.

13:48.460 --> 13:54.820
And now we're gonna open up our animator script because we have all of the reference by now and we are

13:54.820 --> 13:56.260
ready to create the ray.

13:56.260 --> 13:56.430
rate.

13:56.630 --> 14:01.270
So we're going to remove these two, uh slashes forward slashes.

14:01.430 --> 14:04.630
So this physics 2D raycast as a first argument.

14:04.630 --> 14:07.550
It's going to take the point from where we want to shoot out.

14:07.550 --> 14:13.270
So we're going to pass our current checkpoint dot position because from this position we want to shoot

14:13.270 --> 14:14.190
out that way.

14:14.350 --> 14:16.710
And the second thing it's going to take the direction.

14:16.710 --> 14:19.190
So we're going to put this vector to dot down.

14:19.230 --> 14:24.190
Vector two dot down basically means that minus one and -one inch the y.

14:24.230 --> 14:27.190
So it's going to be down and zero in the x.

14:27.190 --> 14:31.750
So since we don't want to shoot out the ray in the x axis or horizontally.

14:31.750 --> 14:34.390
So that's why we pass vector to dot down.

14:34.430 --> 14:38.070
It basically means x into zero and -one inch the y.

14:38.110 --> 14:40.270
So it's going to be in the down direction.

14:40.510 --> 14:45.350
And this and the third argument it's going to take the distance or the length of the ray.

14:45.630 --> 14:49.630
So we're going to pass our distance or basically length of the ray.

14:49.630 --> 14:55.270
And the fourth argument it's going to take the layer mask uh basically which with which game object

14:55.270 --> 14:56.970
we want to check with.

14:56.970 --> 14:58.930
So I'm going to pass my what is ground.

14:58.930 --> 15:01.010
And we do know that what is ground.

15:01.130 --> 15:03.570
Uh, as a I have chosen this crown.

15:03.570 --> 15:04.850
So we're going to check the rate.

15:04.850 --> 15:07.210
Just going to check with that ground game object.

15:07.210 --> 15:12.930
So this function physics 2D dot raycast, it's gonna shoot out the ray from this position in the down

15:12.970 --> 15:14.730
direction with this much of length.

15:14.730 --> 15:16.970
And it's going to check with our ground.

15:16.970 --> 15:18.570
So now what we have to do.

15:18.570 --> 15:22.770
So this right over here, it's gonna give us true or false value.

15:22.770 --> 15:28.410
So what we will do we're going to store it into a raycast variable because this is a ray.

15:28.610 --> 15:32.010
So that's why we need to put it a variable which should be recast.

15:32.050 --> 15:37.850
So what we have to do we need to type this raycast hit variable type hit 2d variable.

15:37.850 --> 15:39.850
And we have to name the parameter.

15:39.850 --> 15:42.770
So we can simply call it something like hit info.

15:43.050 --> 15:44.530
So let's call it hit info.

15:44.530 --> 15:46.530
And let's set equal to this.

15:46.530 --> 15:49.530
So we need to store into this raycast hit 2d.

15:49.570 --> 15:49.970
Why.

15:50.010 --> 15:52.650
Because this physics 2D raycast is a.

15:52.850 --> 15:54.610
It's gonna work like a ray.

15:54.650 --> 15:58.420
So that's why we need to store the result into this array cache.

15:58.420 --> 16:03.220
Hit 2d parameter and we just call it call that parameter.

16:03.220 --> 16:04.060
Hit info.

16:04.260 --> 16:10.500
So this hit info can be true or false depending upon if the array is colliding with this crown or not.

16:10.540 --> 16:13.900
If it's, then this right over here gonna be true.

16:13.900 --> 16:16.420
So that's why this hit info just going to be true.

16:16.420 --> 16:19.300
Because we directly setting it as you can notice.

16:19.660 --> 16:25.740
Uh, and if the ray don't collide with this, uh, this crown, then it's gonna give us false value.

16:25.740 --> 16:28.580
So this right over here, uh, gonna be false.

16:28.580 --> 16:32.020
So that's why this hit info parameter just gonna be false.

16:32.020 --> 16:38.340
So what we want to do now in the next, uh, in the next section, we want to check if the ray don't

16:38.340 --> 16:39.700
collide with that crown.

16:39.700 --> 16:41.060
So what are we gonna do?

16:41.100 --> 16:42.700
We're gonna use this if condition.

16:42.700 --> 16:45.580
So let's make first bracket and some curly brackets.

16:45.580 --> 16:47.340
So what we want to check over here.

16:47.340 --> 16:51.260
We basically want to check if hit info is equals.

16:51.300 --> 16:52.620
Equals to false.

16:52.620 --> 16:56.800
Basically means that this ray that we created from this point.

16:56.800 --> 16:59.240
It's not colliding with this ground game object.

16:59.240 --> 17:03.320
And we do know that if the enemy is somewhere over here.

17:03.320 --> 17:09.800
So if I take my enemy GameObject somewhere here, as you can notice right over here, the rain not gonna

17:09.800 --> 17:12.400
collide at all with this ground game object.

17:12.800 --> 17:19.360
So in that moment, what we're doing, as you can see if I hit info is equals equals to false basically

17:19.360 --> 17:21.080
means the ray is not colliding.

17:21.240 --> 17:24.400
And over here it's not gonna collide at all.

17:24.400 --> 17:25.960
So now what we need to do.

17:26.000 --> 17:30.840
We basically need to flip this enemy to GameObject to the right direction.

17:30.840 --> 17:33.920
But before we do, let's, uh, basically print out a message.

17:33.920 --> 17:40.280
So I'm gonna move my enemy over here and to print out the message, we're going to type this, uh,

17:40.320 --> 17:43.040
debug debug dot log.

17:43.200 --> 17:47.640
And we can simply say something like flip enemy to the right direction.

17:47.640 --> 17:55.120
So let's say something like flip enemy to the right, right direction.

17:55.970 --> 17:57.010
Direction.

17:57.650 --> 17:58.370
Direction.

17:58.370 --> 18:00.530
And let's close that up with semicolon.

18:00.530 --> 18:01.930
So whenever the rain.

18:01.970 --> 18:07.130
Not going to collide with this crown then this message just going to pop up because we're checking over

18:07.130 --> 18:07.650
here.

18:07.650 --> 18:14.810
If hit info equals equals to false basically means that Ray not colliding with that crown game object

18:14.810 --> 18:15.570
at all.

18:15.610 --> 18:18.490
Now I'm going to press Ctrl s to save my script.

18:18.490 --> 18:20.290
And now let's move over to unity.

18:20.530 --> 18:28.010
So as soon as, uh, we will be at the end of this crown, basically that enemy two game object, then

18:28.010 --> 18:33.530
that message just going to pop up right away says, uh, flip enemy to the right direction.

18:33.690 --> 18:37.410
But the problem is that we're not gonna able to see our Ray.

18:37.890 --> 18:44.770
Uh, so as you can see, script just gets compiled, but the problem is that we're not able to see our

18:44.770 --> 18:46.610
way, and we just want to see.

18:46.610 --> 18:48.010
So it's gonna be perfect.

18:48.010 --> 18:54.250
And we do know that in order to create it, we need to use a function calls on draw gizmo selected.

18:54.250 --> 18:59.460
So let's use that in order to see the array or in order to draw the array.

18:59.460 --> 19:02.860
So we're going to open up our animator script by double clicking on it.

19:02.860 --> 19:07.300
And let's go to bottom somewhere over here you can make it anywhere.

19:07.820 --> 19:09.740
It doesn't need to be in order.

19:09.740 --> 19:13.660
So you can just make wherever you would like to go with.

19:13.940 --> 19:17.780
So we have to use this on draw gizmo selected function.

19:17.980 --> 19:20.820
And this function just going to draw what we want to draw.

19:20.820 --> 19:25.980
And this function just unity in build function means a unity just going to call itself.

19:26.140 --> 19:27.780
So we want to draw the array.

19:27.780 --> 19:33.060
But before we want to draw the array we need to check if we assign it this ground check point or not

19:33.700 --> 19:35.260
ground check point or not.

19:35.300 --> 19:38.180
Basically let's use let's draw the array.

19:38.860 --> 19:44.900
So firstly we will check if we assign it that uh basically that ground check point or not.

19:44.900 --> 19:47.660
So what we will do, we will use this if condition.

19:47.660 --> 19:52.420
So let's make first bracket and some curly brackets and what we want to check over here.

19:52.460 --> 19:55.800
We basically want to check if our ground checkpoint.

19:55.800 --> 19:57.840
If it's not equal to null.

19:58.120 --> 19:59.680
What this basically means.

19:59.680 --> 20:03.480
So you need to use this exclamation mark and then this equal sign.

20:03.600 --> 20:10.400
So if ground checkpoint is not equal to null it basically means that this ground check field right over

20:10.400 --> 20:15.000
here underneath our enemy two script is not empty.

20:15.040 --> 20:18.640
Basically we just drag it this ground checkpoint to this ground checkpoint.

20:18.720 --> 20:24.360
So as you can see, if ground checkpoint is not equal to null basically means that we assign it.

20:24.400 --> 20:27.160
So now we're going to draw the draw the ray.

20:27.200 --> 20:32.160
Else we're not going to draw the ray because we need a reference of this ground checkpoint.

20:32.200 --> 20:34.000
After that we can draw the ray.

20:34.040 --> 20:39.360
So that's why before we drawing we're checking if ground checkpoint is not equal to null.

20:39.400 --> 20:44.520
Basically means we just drag it our ground check to ground checkpoint field.

20:44.560 --> 20:47.240
Basically we have the reference of that position.

20:47.240 --> 20:49.680
And now we are ready to draw the ray.

20:49.720 --> 20:52.960
And in order to draw the ray we need to use this gizmos.

20:53.320 --> 21:02.290
Sorry we need to use these gizmos dot draw ray function and this draw ray function as a first argument.

21:02.290 --> 21:05.370
It's going to take the point from where you want to draw.

21:05.370 --> 21:09.850
So we will pass our ground check point and we have to access the position.

21:09.850 --> 21:11.850
So we're going to type this dot position.

21:11.850 --> 21:14.410
And the second thing it's going to take the direction.

21:14.410 --> 21:17.090
So we will pass this vector to dot down.

21:17.130 --> 21:24.890
It's basically means uh minus one is zero in the XX0 in the x and minus one in the y.

21:24.930 --> 21:27.050
So basically means in the down direction.

21:27.250 --> 21:33.490
And we will multiply this, uh, direction with our length of the ray so we can see our ray.

21:33.610 --> 21:39.570
So we will multiply our direction with the length of the ray which is in our case distance.

21:39.570 --> 21:42.090
And now we're going to close that off with semicolon.

21:42.090 --> 21:44.450
So I want to draw with yellow color.

21:44.450 --> 21:48.010
So that's why before I draw I want to specify the color.

21:48.010 --> 21:53.570
If you don't specify then it's just gonna draw the ray with white color.

21:53.570 --> 21:58.740
But if you want to choose a different color so you can do that before you draw the ray.

21:58.900 --> 22:00.620
So I want to choose an.

22:00.660 --> 22:04.780
In order to choose the color, we need to use this gizmos dot color function.

22:04.940 --> 22:06.980
Sorry, this gizmos dot color.

22:07.260 --> 22:10.140
And you can set equal to color that you like.

22:10.140 --> 22:14.940
So I'm going to set color dot yellow a yellow something like that.

22:14.940 --> 22:17.500
And let's close that up with semicolon.

22:17.500 --> 22:21.260
And we're going to press down control S in order to save our scape.

22:21.380 --> 22:26.780
And if we move over to unity as soon as our enemy two script just gonna compiles.

22:26.780 --> 22:34.700
You able to see the ray by now because we just using that on draw gizmo selected function in order to

22:34.740 --> 22:35.660
draw the ray.

22:35.660 --> 22:38.420
So just wait a little moment and you will see that.

22:39.660 --> 22:43.620
And we can play around with the distance basically length of the ray.

22:43.620 --> 22:45.180
And by now we can notice.

22:45.180 --> 22:50.580
So if I select my animator GameObject in the hierarchy and select this move tool in the scene view and

22:50.580 --> 22:53.940
move it somewhere over here, we can see the ray by now.

22:54.080 --> 22:56.960
so I want to make the length a little bit.

22:57.000 --> 22:57.760
I just want to.

22:57.800 --> 22:58.920
Bump up the value.

22:59.040 --> 23:03.440
So I will move over to this distance parameter underneath my animator script.

23:03.440 --> 23:05.640
And let's make it something around one.

23:05.840 --> 23:07.000
And this is fine.

23:07.000 --> 23:09.200
So I'm gonna move it somewhere around here.

23:09.400 --> 23:15.680
And if the enemy is somewhere around here, so they're not gonna collide with this game object.

23:15.680 --> 23:20.360
So that message just going to pop up says flip enemy to the right direction.

23:20.360 --> 23:21.680
So let's have a look on that.

23:21.680 --> 23:23.520
So I'm going to select my console tab.

23:23.520 --> 23:27.600
And let's click on this play button in the top in order to play our game.

23:27.960 --> 23:35.240
And you will see as soon as we will be at the end of the edge of the of this ground, you will see that

23:35.240 --> 23:39.840
message just going to pop up says flip enemy to the right direction.

23:40.760 --> 23:43.560
So if I just jump over, you will see.

23:43.920 --> 23:50.080
As you can see, as soon as we we are here, the message just gets pop up.

23:50.080 --> 23:54.650
And still the message just getting pop up says flip enemy to the right direction.

23:54.650 --> 23:54.970
Why?

23:55.010 --> 23:58.730
Because the ray not colliding with this ground, as you can see.

23:58.970 --> 24:01.050
So I'm gonna get out of play mode.

24:01.050 --> 24:05.650
So instead of doing this, we need to flip this enemy to the right direction.

24:05.650 --> 24:12.130
So if I select my enemy to GameObject in the hierarchy, then go over to Inspector Transform and Rotation

24:12.410 --> 24:14.450
add rotation and in the y.

24:14.490 --> 24:22.090
If I put 180 or -180, as you can see, as soon as we put it, it flips to the right direction.

24:22.090 --> 24:25.010
So we basically need to change the Euler angles.

24:25.010 --> 24:31.090
So we basically do gonna do the same thing as we have done with our enemy one game object.

24:31.090 --> 24:33.330
So we're gonna approach the same way.

24:33.370 --> 24:34.930
So I'm going to set back to zero.

24:35.130 --> 24:38.690
So to do that instead of printing out message we need to flip.

24:38.850 --> 24:43.090
So let's double click on this message in order to move over to that line of code.

24:43.090 --> 24:46.930
So instead of printing out message we just want to flip.

24:47.090 --> 24:48.530
And in order to flip.

24:48.530 --> 24:52.050
But before we flip we need to check which direction we going.

24:52.250 --> 24:57.110
So as you can notice, this enemy just facing to facing left.

24:57.150 --> 25:01.030
Basically this enemy looking to the left direction.

25:01.030 --> 25:06.630
So before we flip, we also need to check in which direction this enemy is facing.

25:06.910 --> 25:09.950
So before we flip we will check.

25:10.150 --> 25:11.790
So let's use this if condition.

25:11.830 --> 25:14.430
Let's make first bracket and some curly brackets.

25:14.430 --> 25:16.270
And what we want to check over here.

25:16.270 --> 25:21.230
We basically want to check if facing left is true equals equals to true.

25:21.470 --> 25:27.350
Or you can just leave like this basically means that this enemy is looking to the left direction.

25:27.350 --> 25:31.590
So what we need to do now so the enemy is gonna be over here.

25:31.590 --> 25:34.670
So basically we need to move over to Euler angles.

25:34.670 --> 25:37.550
And we need to set the y to -180.

25:37.590 --> 25:41.630
And we do know once we're gonna set that it's going to flip to the right direction.

25:41.630 --> 25:46.830
And after flipping to the right direction we need to set that facing left parameter to false.

25:46.830 --> 25:47.230
Why?

25:47.390 --> 25:53.640
Because if I set it to -180 or 180 sorry Of 180.

25:54.000 --> 25:59.840
So in this situation, this enemy will no longer just gonna face to the left direction.

25:59.840 --> 26:05.240
So that's why after flipping this enemy, we need to set the facing left parameter to false.

26:05.240 --> 26:10.960
Because in that moment, this enemy would two game object just gonna look to the right direction.

26:10.960 --> 26:11.680
So that's why.

26:11.680 --> 26:13.240
So I'm going to set back to zero.

26:13.640 --> 26:16.120
And let's move it somewhere around here.

26:16.280 --> 26:18.000
And let's go to our script.

26:18.000 --> 26:23.560
So to flip that we need to use this transform then dot Euler angles.

26:23.560 --> 26:27.640
And this is going to have x x y and z angle.

26:27.840 --> 26:29.400
So sorry z axis.

26:29.400 --> 26:33.080
So we're going to set equal to new vector three which also going to have.

26:33.080 --> 26:38.000
So which also gonna have x axis y axis and the z axis.

26:38.000 --> 26:43.960
So in the y what we need to do we need to put a we basically need to put one ATF.

26:44.120 --> 26:50.560
And we do know that as soon as we're gonna put one ATF minus one ATF, it's gonna flip to the right

26:50.560 --> 26:51.200
direction.

26:51.200 --> 26:54.170
And we don't want to mess around z axis.

26:54.170 --> 26:56.570
So we're going to put zero f in Z.

26:56.570 --> 26:59.930
And we're going to do the same thing in the x axis zero f.

27:00.130 --> 27:04.530
And now after flipping this we need to set this facing left parameter to false.

27:04.570 --> 27:05.010
Why?

27:05.170 --> 27:10.450
Because as soon as we're gonna flip this enemy to the right direction, it's no longer able to look

27:10.450 --> 27:11.690
to the left direction.

27:11.690 --> 27:17.210
So that's why after flipping this, now, we're gonna set facing left equal to false.

27:17.730 --> 27:18.090
False.

27:18.130 --> 27:20.330
And let's close that up with semicolon.

27:20.330 --> 27:24.810
And now I'm going to press down Ctrl s on my keyboard in order to save my script.

27:24.810 --> 27:26.570
And then move over to unity.

27:26.610 --> 27:33.170
You will see as soon as this enemy is just going to be at the end of this crown, this enemy just kind

27:33.170 --> 27:35.210
of flips to the right direction.

27:35.730 --> 27:37.370
So let's have a look on that.

27:37.370 --> 27:44.610
So just wait a moment and I'm going to take this enemy over here and let's have a look.

27:44.610 --> 27:47.050
So let's click on this play button in the top.

27:47.050 --> 27:49.130
And in order to play our game.

27:49.130 --> 27:51.010
And let's take a look on this.

27:56.830 --> 27:58.430
So just wait a moment.

27:59.870 --> 28:01.510
And if we jump over.

28:01.510 --> 28:04.150
So it's gonna flip as soon as we can see.

28:04.190 --> 28:11.230
As soon as enemy was over here, it just get flipped to the right direction and we can see if we just

28:11.230 --> 28:16.550
select my enemy two GameObject in the hierarchy, move over to Inspector Transform and Rotation.

28:16.550 --> 28:19.150
We can see in the Y is 180.

28:19.350 --> 28:27.270
And now if the enemy is somewhere over here, we again need to set the Y to zero.

28:27.430 --> 28:33.630
So what we basically have to do if the enemy is over here, let's suppose it's looking to the right

28:33.630 --> 28:34.390
direction.

28:34.390 --> 28:36.790
So enemy just gonna be over here.

28:36.790 --> 28:40.390
So they're not gonna collide with this ground game object at all.

28:40.390 --> 28:44.230
So what we need to do now, we need to set back y to zero.

28:44.230 --> 28:50.150
And we do know that if we set back to zero, we can see this enemy just gonna look to the left direction

28:50.190 --> 28:51.510
one more time.

28:51.510 --> 28:57.960
So we need to set back to zero as well as after, uh, flipping this enemy to the left direction, we

28:57.960 --> 29:00.640
need to set that facing left parameter to true.

29:01.040 --> 29:01.400
Why?

29:01.640 --> 29:06.680
Because as you can see, as soon as we're gonna flip to the left direction, we will look to the left

29:06.680 --> 29:07.200
direction.

29:07.200 --> 29:11.200
So that's why we need to set that parameter one more time to true.

29:11.200 --> 29:14.280
So that's why we created that facing layer parameter.

29:14.280 --> 29:19.680
In order to check which direction this enemy to game object is facing.

29:19.840 --> 29:21.360
So basically that is the thing.

29:21.360 --> 29:22.440
So let's do it.

29:22.440 --> 29:26.400
So now what we're going to do, we're going to open up our enemy script once again.

29:26.400 --> 29:35.400
And we will check else if our enemy if our enemy looking to the left or sorry if our enemy is looking

29:35.440 --> 29:36.840
to the right direction.

29:36.880 --> 29:42.600
So then what we're going to do, we we can simply copy this line of code by Ctrl C, and we can simply

29:42.600 --> 29:44.720
paste it over here by Ctrl V.

29:44.960 --> 29:48.480
So in the Y what we can do, we can simply put zero f.

29:48.480 --> 29:53.810
And we do know that as soon as we're going to put zero F it's gonna flip to the left direction.

29:53.810 --> 29:58.970
And after flipping to the left direction, we're gonna set this facing left parameter right over here

29:58.970 --> 30:00.930
to true once again.

30:00.930 --> 30:02.450
So we're gonna set it to true.

30:02.450 --> 30:06.050
So firstly what we're checking we're checking if hit info is false.

30:06.050 --> 30:09.730
Basically means the array is not colliding with this ground.

30:09.730 --> 30:13.930
And in the else condition we're checking if we're looking to the right direction.

30:13.930 --> 30:16.210
Then we're setting again to zero.

30:16.610 --> 30:20.690
And after that we're setting facing left parameter to true as you can see.

30:20.890 --> 30:22.650
So now we are done.

30:22.810 --> 30:30.210
And let's press down Ctrl S to save our script I'm going to press Ctrl S to save my escape.

30:30.290 --> 30:32.410
And now let's move over to unity.

30:32.410 --> 30:37.090
So you will able to notice this armature schooner petrel around this ground.

30:37.290 --> 30:37.890
Uh ground.

30:37.930 --> 30:39.730
It's one one.

30:39.930 --> 30:43.890
It's gonna gonna be at the end of the left direction.

30:43.890 --> 30:46.010
It's gonna flip to the right direction.

30:46.050 --> 30:49.730
Basically, this enemy is just gonna start moving to the right direction.

30:49.730 --> 30:53.070
If the enemy to Two is something over here.

30:53.070 --> 30:54.310
So let's check it.

30:54.310 --> 30:58.550
And let's click on this play button in the top in order to play our game.

30:58.550 --> 31:00.510
And let's take a look on this.

31:00.510 --> 31:06.510
So this anime two is just gonna patrol around this ground, uh, depending upon which direction it's

31:06.510 --> 31:06.870
going.

31:06.910 --> 31:09.750
If it's at the end, then it's gonna flip itself.

31:09.950 --> 31:11.270
So let's have a look.

31:11.270 --> 31:15.350
So if I jump over it, we can see it's gonna flip.

31:15.350 --> 31:17.430
Now it's flipped to the right direction.

31:17.710 --> 31:24.270
And if we if the enemy is here, it's gonna flip one more time to the left direction, as you can see.

31:24.310 --> 31:24.830
Indeed.

31:25.230 --> 31:30.990
And if I pause my game by clicking on this pause button in the top, then go over to Inspector.

31:31.030 --> 31:35.670
As you can see in the Y, we just set rotation back to zero.

31:35.950 --> 31:42.710
And if if you want to see that private parameter which is bool parameter that we created which is facing

31:42.710 --> 31:45.310
left, then you need to move over to inspector.

31:45.310 --> 31:47.230
In the top right you can see three dots.

31:47.230 --> 31:50.190
So just click there and then click on this debug mode.

31:50.190 --> 31:54.840
And now we're going to able to notice our, uh, private parameters.

31:54.840 --> 32:00.760
And we can see facing left as soon as we click on that debug mode underneath our enemy two script,

32:00.760 --> 32:02.960
we can notice facing left is checked.

32:02.960 --> 32:07.160
Basically means we just set back to true, uh, set back to true.

32:07.160 --> 32:08.680
And we can check that out.

32:08.680 --> 32:14.280
And you will see this parameter just going to be uncheck or check basically means true or false depending

32:14.280 --> 32:17.040
upon which direction this enemy is going.

32:17.080 --> 32:23.280
As you can see, as soon as enemy is over here then this facing left just getting true because it's

32:23.280 --> 32:24.880
looking to the left direction.

32:24.880 --> 32:33.480
And once the enemy, sorry, once the enemy is, uh, somewhere around here, uh, then the facing left

32:33.520 --> 32:39.840
just gets false because this enemy just flips to the right direction, as you can notice underneath

32:39.840 --> 32:41.160
your enemy to script.

32:41.160 --> 32:45.840
And let's suppose you just want to go back in inspector mode then what you can do.

32:45.840 --> 32:50.120
So firstly I'm going to get out of play mode by clicking on this play button in the top.

32:50.360 --> 32:51.340
And to go back.

32:51.380 --> 32:55.700
Just go over to Inspector one more time and then go over to top right.

32:55.700 --> 33:01.620
Click on that three dots and then click on this normal in order to go back in normal mode.

33:01.980 --> 33:10.260
And one thing I have to mention that if you don't use this hit info, basically, if you just put exclamation

33:10.260 --> 33:15.420
mark right in front of this hit info parameter, it basically means the same thing.

33:15.460 --> 33:17.820
Basically means hit info is false.

33:17.820 --> 33:21.860
So you can simply just put this exclamation mark.

33:21.900 --> 33:25.660
It basically means false or it's basically the same thing.

33:25.780 --> 33:29.300
Hit info equals equals to false means the same thing.

33:29.580 --> 33:35.340
So I hope you get the idea that how you can do it and make sure if you change anything inside this anime

33:35.620 --> 33:40.300
script in the hierarchy, then go over to Inspector Overrides and then apply all.

33:40.460 --> 33:47.020
And also you also press down Ctrl S on your keyboard in order to save your project.

33:48.500 --> 33:51.500
So I hope you get the idea that how you can do it.
