WEBVTT

00:00.080 --> 00:01.560
Let's create some traps.

00:01.600 --> 00:03.720
Game object basically traps.

00:03.720 --> 00:06.600
To do that, I'm going to head over to my project app.

00:06.600 --> 00:07.600
Then assets.

00:07.600 --> 00:12.880
I will head over to my sprites folder, then Pixel Adventure one folder.

00:12.880 --> 00:14.120
So just wait a minute.

00:14.520 --> 00:16.480
I'm going to make this like this.

00:16.480 --> 00:18.880
And let's move over to sprites folder.

00:19.160 --> 00:25.960
Then Pixel Adventure one folder and I have three folder inside there sub folder.

00:26.160 --> 00:30.160
And let's go to traps and let's select the sofas.

00:30.240 --> 00:32.640
So we're going to deal with the sofa first.

00:32.640 --> 00:34.840
So let's select the sprite sheet.

00:34.840 --> 00:36.160
Let's go over to Inspector.

00:36.160 --> 00:39.280
Let's click on this open Sprite editor editor.

00:39.520 --> 00:41.560
So let's slice this individually.

00:41.560 --> 00:46.000
So pixel per unit we're going to choose 16 filter mode to point no filter.

00:46.000 --> 00:49.920
And then click on this apply button and make sure sprite mode to multi.

00:49.960 --> 00:52.720
Because we're going to slice individually.

00:53.160 --> 00:57.800
Instead of slicing automatic we're going to move over to our Sprite Editor tab.

00:57.800 --> 01:02.100
Let's click on this slice and we're going to select automatic to read by cell count.

01:02.100 --> 01:04.980
And let's count how many columns and rows we have.

01:05.020 --> 01:08.060
We can see one row and four columns.

01:08.060 --> 01:11.100
So we're going to put eight columns and one row.

01:11.260 --> 01:15.900
And after doing that let's click on this slice button and then click on this apply button.

01:15.900 --> 01:18.260
And I'm going to choose my game view once again.

01:18.300 --> 01:20.180
And let's go over to that spreadsheet.

01:20.180 --> 01:23.500
Click on this arrow in order to see the individual sprite.

01:23.660 --> 01:29.900
And in the bottom right you can see in your project tab you can just scale this up like this.

01:30.260 --> 01:31.940
It's up to you basically.

01:32.260 --> 01:34.140
So I'm going to select the first sprite.

01:34.140 --> 01:37.580
Let's drag it over to the scene view or into this hierarchy.

01:37.580 --> 01:38.940
So I'm going to select that.

01:38.940 --> 01:42.300
Let's drag it over to the scene view or into this hierarchy.

01:42.460 --> 01:45.300
As you can see we have our shop.

01:45.500 --> 01:47.340
So let's call it something like shop.

01:47.340 --> 01:51.540
So let's go over to Inspector and let's call this one store.

01:51.780 --> 01:56.260
And we're going to add some some components to this shop game object.

01:56.260 --> 02:01.960
First thing we're going to add a rigid body 2D and we will set the gravity scale to zero, so it's not

02:01.960 --> 02:03.520
gonna fall down at all.

02:03.720 --> 02:09.840
Second, uh, second component we're gonna add a circle collider 2D for collision detection.

02:10.040 --> 02:12.200
So let's click on this add component.

02:12.200 --> 02:16.040
But before you do, make sure you select your GameObject in the hierarchy.

02:16.240 --> 02:19.760
Then go over to Inspector and then click on this add component.

02:19.960 --> 02:22.160
And we're gonna add a rigid body 2D.

02:22.160 --> 02:24.760
So let's type that and it's going to pop up.

02:24.960 --> 02:30.320
And as soon as it's gonna pop up we just gonna click on it in order to attach that.

02:30.320 --> 02:32.840
And now we're going to set the gravity scale to zero.

02:32.840 --> 02:36.600
So let's set this to zero and collision detection.

02:36.600 --> 02:40.240
We're gonna choose continuous and interpolate to interpolate.

02:40.400 --> 02:43.280
And we can freeze the rotation about z axis.

02:43.280 --> 02:45.280
Or we can just skip it that.

02:45.480 --> 02:50.040
So now let's click on this rigid body one more time just to collapse at once.

02:50.040 --> 02:52.160
And let's click on this add component.

02:52.160 --> 02:55.040
And now we're going to add a circle Collider 2D.

02:55.040 --> 02:57.680
So let's type that circle Collider 2D.

02:58.040 --> 03:03.060
Or we can just go over to, uh, Collider 2D and we can just add that up.

03:03.060 --> 03:11.340
So let's attach this circle, Collider 2D, and we need to adjust the collider as the size of our sprite.

03:11.340 --> 03:15.380
So we're going to move over to Inspector and then click on this Edit Collider.

03:15.380 --> 03:18.580
I just want to make the radius a little bit smaller.

03:18.580 --> 03:23.780
So I'm going to move over to my radius uh inside this circle Collider 2D component.

03:24.060 --> 03:28.420
And let's make it something like 11.1.

03:28.420 --> 03:30.180
Let's make it 1.1.

03:30.180 --> 03:31.140
And then Simms.

03:31.140 --> 03:31.860
Perfect.

03:31.860 --> 03:34.100
And we're going to assign this circle Collider.

03:34.140 --> 03:39.260
Sorry this game object as a trap game object since this is going to be a trap.

03:39.260 --> 03:44.300
So that's why we're going to assign this so game object as a trap tag.

03:44.340 --> 03:46.620
To do that we will go over to Inspector.

03:46.620 --> 03:50.700
Let's click on this tag and then click on this add tag.

03:50.820 --> 03:53.260
And let's create a new tag for our show.

03:53.260 --> 03:55.100
So let's click on this plus icon.

03:55.300 --> 03:58.930
And we're going to no sorry we're not gonna name it to something like.

03:58.930 --> 03:59.290
So.

03:59.370 --> 04:04.010
Instead, we're gonna call it trap because we're gonna have multiple traps, so that's why.

04:04.250 --> 04:10.570
So let's call this one trap, and let's click on the save button and then select your game object.

04:10.570 --> 04:15.530
Then go over to Inspector and Assign with the tag which you recently created.

04:15.530 --> 04:18.370
So I assigned this game object as a trap.

04:18.370 --> 04:20.770
As you can notice in Inspector.

04:20.770 --> 04:24.450
So I assigned this game object as a trap tag.

04:24.490 --> 04:26.130
And now we can just go ahead.

04:26.130 --> 04:30.210
We can and then we can and we can just make the animation.

04:30.210 --> 04:31.730
So let's make the animation.

04:31.730 --> 04:38.090
So to make the animation we will move over to our project app assets and then sprites folder.

04:38.090 --> 04:40.970
And we will head over to that folder.

04:40.970 --> 04:43.410
And then we will head over to Source folder.

04:43.970 --> 04:46.330
There we can see we have the sprite sheet.

04:46.330 --> 04:52.050
So just click in this arrow to see the individual and select all of them by holding down shift.

04:52.050 --> 04:58.550
And then and then drag it over to this game object on top of this object in the hierarchy.

04:58.710 --> 05:01.310
In order to make the animation right away.

05:01.630 --> 05:03.750
So just wait a little moment.

05:03.750 --> 05:05.310
It's lagging a little bit.

05:05.510 --> 05:09.070
So we need to place the animation where we want to place it.

05:09.070 --> 05:14.750
So for that I'm going to just click on this double arrow in the top left side we can see and let's click

05:14.750 --> 05:16.630
on this assets in assets.

05:16.630 --> 05:20.390
We already created a animation folder as you can notice.

05:20.390 --> 05:23.150
So we're going to open that up by double clicking on it.

05:23.150 --> 05:27.590
And let's uh let's create a sub folder for our traps.

05:27.590 --> 05:31.990
So let's right click and then new and folder.

05:31.990 --> 05:35.310
And we're going to call this folder to something like traps folder.

05:35.630 --> 05:41.830
So let's call it traps underscore underscore animation animation.

05:41.830 --> 05:45.710
And let's open up this sub folder by double clicking on it.

05:46.070 --> 05:47.670
So just bit wait.

05:47.790 --> 05:49.190
So I really apologize.

05:49.190 --> 05:50.990
It's just lagging a little bit.

05:50.990 --> 05:53.670
So let's open that up by double clicking on it.

05:53.670 --> 05:55.770
And we have to name the animation.

05:55.770 --> 05:58.770
So this will be show, uh, and it's gonna spin.

05:58.770 --> 06:01.130
So I'm going to call it simply something like so.

06:01.130 --> 06:02.290
So let's call it so.

06:02.330 --> 06:05.290
And after doing that let's click on the save button.

06:05.290 --> 06:10.650
And now if we click on this save button and then select our show GameObject in the hierarchy.

06:10.690 --> 06:12.730
Then move over to the animation tab.

06:12.770 --> 06:17.970
You will notice that this GameObject just gonna spin around itself.

06:17.970 --> 06:21.850
So just wait a moment and you will be able to notice that.

06:22.290 --> 06:27.290
So just wait a moment and once it's done, we can just go ahead and check that out.

06:27.330 --> 06:31.130
As you can notice we just created the animation.

06:31.130 --> 06:33.890
So I'm going to select my shock GameObject in the hierarchy.

06:33.890 --> 06:36.290
And let's move over to this animation tab.

06:36.290 --> 06:42.370
In order to check the animation, let's click on this play button in animation tab.

06:42.370 --> 06:50.130
And indeed we can notice that this shock GameObject just rotating itself in the z axis as you can notice.

06:50.130 --> 06:58.230
So we just created and also let's create a script in order to move this game object between 2 or 3 points.

06:58.230 --> 07:02.630
Even more than that, points even more than 5 or 10 points.

07:02.630 --> 07:09.470
It's basically up to you how many points you just want to move your traps or this game object.

07:09.470 --> 07:11.550
For that, we need to create a script.

07:11.550 --> 07:14.710
To do that, we will head over to our project tab.

07:15.030 --> 07:18.750
Then we will head over to assets folder and then Script Folder.

07:18.790 --> 07:22.750
Let's right click there, then create, then Monobehaviour script.

07:22.790 --> 07:25.270
And you can name that script to something like Shaw.

07:25.310 --> 07:28.070
It's up to you, whatever you want to call it.

07:28.070 --> 07:33.870
I already created a script called so and I have it right over here as you can notice.

07:33.870 --> 07:36.750
So I'm going to select my game object in the hierarchy.

07:36.910 --> 07:42.350
And let's select this script and drag it over to this add component section and Inspector.

07:42.350 --> 07:45.230
Or you can simply click on this add component.

07:45.230 --> 07:48.270
And you can find the script by typing the name of the script.

07:48.270 --> 07:51.430
And then click on it in order to attach that.

07:51.670 --> 07:56.130
So we want to move Uh, our shock ammo check between two points.

07:56.130 --> 07:58.010
So let's create those two points.

07:58.010 --> 08:00.690
To do that, I'm going to move over to my hierarchy.

08:00.690 --> 08:01.770
Let's right click.

08:01.770 --> 08:04.570
Let's firstly create an empty parent game object.

08:04.570 --> 08:10.810
And inside that parent game object we're going to create two child game object to just keep our hierarchy

08:10.850 --> 08:12.010
a little bit clean.

08:12.250 --> 08:15.210
So we're going to create an empty parent game object first.

08:15.210 --> 08:18.330
And let's call this GameObject to something like points.

08:18.330 --> 08:22.930
So let's call it points and then go over to Inspector then transform.

08:22.930 --> 08:25.330
Then right click transform and then reset.

08:25.570 --> 08:31.130
And if you want to choose an uh gizmos or icon then go over to Inspector.

08:31.130 --> 08:33.170
Click here in this box.

08:33.170 --> 08:36.130
And then we're going to choose this yellow or anything like that.

08:36.490 --> 08:37.810
Let's click on this.

08:38.770 --> 08:41.290
I guess we are able to see.

08:43.570 --> 08:44.530
I don't know.

08:46.970 --> 08:47.490
Okay.

08:47.530 --> 08:48.370
That's fine.

08:48.370 --> 08:49.530
We can just okay.

08:49.570 --> 08:51.050
We have it over here.

08:51.250 --> 08:54.070
So now as you can see we created this point.

08:54.230 --> 08:55.470
Points game object.

08:55.510 --> 08:58.750
Now we're gonna create two tile game object or two points.

08:58.750 --> 09:04.030
In order to move this swap between those two points or more than two points.

09:04.230 --> 09:06.470
So let's right click on this point game object.

09:06.470 --> 09:08.590
Let's create an empty game object.

09:08.590 --> 09:12.790
And we can call this one first point or let's simply call it one.

09:12.790 --> 09:15.470
And now we're going to select the move tool in the scene view.

09:15.470 --> 09:17.470
And let's select that game object.

09:17.470 --> 09:20.150
And let's move it somewhere around here.

09:20.390 --> 09:24.190
And if you want to choose any gizmos for it then go over to Inspector.

09:24.190 --> 09:24.990
Click here.

09:24.990 --> 09:26.990
And we're gonna choose this yellow one.

09:26.990 --> 09:34.390
As you can notice right over here we have and let's duplicate this one in order to create the second

09:34.390 --> 09:34.950
point.

09:34.990 --> 09:40.510
To do that I'm going to select my one game object underneath my points GameObject in the hierarchy.

09:40.910 --> 09:44.390
Let's select that and we're going to press down Ctrl D to duplicate.

09:44.390 --> 09:47.270
And let's move it down somewhere over here.

09:47.270 --> 09:53.700
So between these two points we just want to move our at this raw game object and let's call the duplicate

09:53.700 --> 09:57.700
point, uh, point to something like two, uh, like that.

09:57.700 --> 10:02.020
So that's why we created an empty parent game object, as you can see.

10:02.060 --> 10:07.420
And inside that parent game object, we just created these two child game object or these two points.

10:07.420 --> 10:09.740
And we can just click over here to collapse.

10:09.780 --> 10:13.660
As you can see now our hierarchy seems a lot more clean.

10:13.660 --> 10:17.420
So that's why we just created an empty parent game object first.

10:17.420 --> 10:21.740
And inside that parent game object we just created two child game object.

10:21.740 --> 10:25.220
Or you can simply say these two points or position.

10:25.580 --> 10:31.460
And I'm going to select Mysore and let's move it somewhere over here like that.

10:31.460 --> 10:35.060
And we can just go ahead and we can open up our script.

10:35.060 --> 10:37.060
So we're going to open up our source script.

10:37.180 --> 10:40.500
Uh, so let's select our source GameObject in the hierarchy.

10:40.540 --> 10:45.140
Let's go over to Inspector and let's open up the source script by double clicking on it.

10:45.300 --> 10:49.420
And what we need, we basically need a reference both of those point.

10:49.420 --> 10:52.720
So we can just move between those two points.

10:52.840 --> 10:58.080
So what we will do, we will go to top of our class, uh, class.

10:58.080 --> 11:02.880
And over here we're going to make a serialized field and that will be transformed.

11:03.000 --> 11:04.960
So let's make it over here.

11:05.280 --> 11:07.560
So let's make a serialized field.

11:08.880 --> 11:09.480
Sorry.

11:10.080 --> 11:11.920
Serialized field.

11:13.600 --> 11:14.600
Serialized field.

11:14.880 --> 11:15.600
Sorry.

11:15.640 --> 11:17.840
I really apologize for that.

11:18.640 --> 11:19.040
Okay.

11:19.080 --> 11:20.240
Serialized field.

11:20.440 --> 11:22.400
And this will be private.

11:22.440 --> 11:24.560
We're going to mark private instead.

11:24.560 --> 11:26.200
Even we made it private.

11:26.240 --> 11:32.360
We are gonna able to notice, since we just mark mark it as a serialized field.

11:32.400 --> 11:35.160
As you can notice, and we need a reference.

11:35.480 --> 11:36.840
Both of these points.

11:36.840 --> 11:40.680
We need both of these points, this first point and the second point.

11:40.920 --> 11:42.800
Or you can simply say position.

11:42.800 --> 11:48.240
So we need to type transform because transform we don't know it's responsible for position.

11:48.240 --> 11:49.720
So we're going to type transform.

11:49.720 --> 11:54.780
And we can call points, but we have more than one point, as you can notice.

11:55.060 --> 11:59.380
Uh, as you can notice, we have this first point and the second point.

11:59.380 --> 12:01.940
So we basically need to create an array.

12:02.100 --> 12:06.580
So basically right after this transform you basically need to make this brackets.

12:06.580 --> 12:08.100
And now this is an array.

12:08.300 --> 12:12.060
An array basically you can uh you can put multiple things.

12:12.060 --> 12:16.020
It can be anything like game object numbers even position.

12:16.020 --> 12:20.380
So that's why we just made this array basically square brackets.

12:20.380 --> 12:23.300
And we have to name the array what we want to name it.

12:23.300 --> 12:25.580
So we're going to call it something like points.

12:25.580 --> 12:27.900
And let's close that up with semicolon.

12:27.900 --> 12:33.340
And now we just created our points array basically a variable.

12:33.340 --> 12:35.220
And we're going to put our first point.

12:35.220 --> 12:39.820
And the second point inside this array that we created which is our points.

12:39.820 --> 12:42.980
So now I'm going to press down Ctrl s to save my script.

12:43.020 --> 12:47.540
And now let's move over to unity in order to save our script.

12:47.540 --> 12:49.520
And we need to assign those points.

12:49.520 --> 12:51.560
So we just created an array.

12:51.560 --> 12:55.560
And we do know that array is basically a parameter type.

12:55.560 --> 12:58.040
But it can hold up multiple values.

12:58.040 --> 12:59.320
It can be numbers.

12:59.320 --> 13:00.560
It can be names.

13:00.560 --> 13:01.680
It can be position.

13:01.680 --> 13:04.240
It can be, uh, anything like that.

13:04.240 --> 13:08.440
So you need to make square brackets right after your transform you making.

13:08.440 --> 13:10.240
So make sure you just do that.

13:10.480 --> 13:13.280
And that's basically reference our array.

13:13.600 --> 13:15.880
And we need to take one by one point.

13:15.880 --> 13:18.720
And we can simply just drag it into this array.

13:18.960 --> 13:25.280
And in the start of the end basically once our source script just gonna compile completely, uh, our

13:25.320 --> 13:26.680
array is just gonna be empty.

13:26.800 --> 13:32.320
So we need to put, uh, both of these point the first point and the second point into that array,

13:32.760 --> 13:34.160
and you will see that.

13:34.160 --> 13:40.600
So just wait a moment and once our compilation is done, we can just go ahead and we can just assign

13:40.600 --> 13:46.360
those points, or we can just store the first point and the second point into that points array that

13:46.360 --> 13:49.740
we created inside our C script.

13:49.740 --> 13:55.860
So just wait a moment to compile our script, and once it's done, we can just go ahead and we can assign

13:55.860 --> 14:02.820
those, uh, assign those, or we can simply drag one by one, uh, into that points array.

14:03.220 --> 14:09.180
So as soon as our, uh, script compiles, as you can notice points and it says zero.

14:09.180 --> 14:13.460
So what we can do, we can just move over to hierarchy than points game object.

14:13.460 --> 14:17.980
And we can select the first point and drag it over to this points uh array.

14:17.980 --> 14:22.580
And then we're going to select the second one and let's drag it over to this points array.

14:22.740 --> 14:25.540
Now we can notice we have the both of these points.

14:25.740 --> 14:33.020
Uh so this first point basically the top one we can see it's assigned with a zero index as you can see.

14:33.060 --> 14:37.540
And the bottom position or the second position we can see index is one.

14:37.540 --> 14:40.900
So both of these position just get assigned with an index.

14:40.900 --> 14:46.340
So the top position or the first uh first position index or the point uh point index.

14:46.340 --> 14:49.880
We can notice it's zero and the second one is one.

14:49.880 --> 14:52.960
So let's suppose we want to move to the first point.

14:52.960 --> 14:56.320
So what we need to do we basically need to pass our zero.

14:56.320 --> 15:01.640
So in order to move our show game object we basically need to open up our script.

15:01.640 --> 15:04.800
So let's double click on it in order to open that up.

15:04.800 --> 15:07.040
And we will go to top of our class.

15:07.040 --> 15:12.320
And we're going to declare a private variable to just keep track of which point we are in.

15:12.520 --> 15:17.160
And we do know that if the index is zero, it's going to be the first point.

15:17.160 --> 15:21.840
And if the index is one basically means the second point or the bottom point.

15:21.840 --> 15:26.120
So we're going to make a variable to just keep track of which point we are in.

15:26.120 --> 15:27.960
So we're going to make a private.

15:27.960 --> 15:30.400
And that will be in like 0123.

15:30.400 --> 15:33.880
And we can call this one index point point index.

15:33.920 --> 15:38.440
Let's call it simply point index point index.

15:38.440 --> 15:40.760
And let's close that up with semicolon.

15:40.760 --> 15:44.480
And now what I'm going to do I'm going to move over to my start function.

15:44.480 --> 15:45.640
So this is a start function.

15:45.640 --> 15:48.510
Get call in the start of the game and the start of the game.

15:48.510 --> 15:50.830
I'm gonna set this point index to zero.

15:50.830 --> 15:55.750
So I'm going to set point index sorry point index equal to zero.

15:56.110 --> 15:58.510
And let's close that up with semicolon.

15:58.510 --> 16:02.030
And now what we're going to do we're going to move over to this update function.

16:02.030 --> 16:05.590
And we do know that this update function runs every single frame.

16:05.590 --> 16:10.470
So every single frame we need to move over this short game object between these two points.

16:10.470 --> 16:12.750
So we want to move to the first point.

16:12.750 --> 16:15.190
So as index we're going to pass zero.

16:15.190 --> 16:19.470
So in order to move that what we need to do we need to use a function.

16:19.470 --> 16:23.510
And it's called it's called vector2 dot move towards.

16:23.510 --> 16:26.470
But before we do we need to set the current position.

16:26.470 --> 16:30.710
So we will go to transform dot position and transform dot position.

16:30.710 --> 16:33.990
Right over here basically means the current position of that.

16:33.990 --> 16:40.390
So game object basically this game object current position as you can notice in the inspector.

16:40.670 --> 16:45.190
And so what we're gonna do we're gonna set the current position equal to vector two.

16:45.690 --> 16:49.050
a vector2 dot move towards function vector two dot.

16:49.690 --> 16:55.490
Sorry, you need to use this function and this vector to dot move towards function as a first argument.

16:55.490 --> 17:00.330
It's going to take the take the current position where you are in.

17:00.330 --> 17:05.250
So we're going to pass our transform dot position which basically means our current position.

17:05.250 --> 17:09.770
And the second it's going to take the target position or via equipment to go.

17:09.770 --> 17:11.930
So we're going to pass our points array.

17:11.930 --> 17:14.690
So we basically need to type our points array.

17:14.690 --> 17:18.170
Or basically we have to type the point points array.

17:18.210 --> 17:20.650
Or basically we need to pass our array.

17:20.770 --> 17:22.730
And then we need to make these brackets.

17:22.730 --> 17:27.810
And inside this bracket you have to put the index a put.

17:27.930 --> 17:31.970
You can put the index that you just want to move over to that point.

17:31.970 --> 17:35.330
So I'm going to pass my point index I just created.

17:35.330 --> 17:40.090
And make sure right after this square brackets you need to type the dot position.

17:40.090 --> 17:45.270
Because this this basically this array is a Transform array.

17:45.270 --> 17:47.710
Or you can simply say position array.

17:47.830 --> 17:53.350
And the third argument is going to take the speed with how much speed you just want to move over to

17:53.390 --> 17:54.150
that point.

17:54.150 --> 17:57.110
So we're going to declare a variable for our speed.

17:57.110 --> 18:02.830
So let's go to the top of our class and let's make another serialized field and private.

18:03.030 --> 18:04.550
And this will be float.

18:04.550 --> 18:07.390
And we can call this one something like move speed.

18:07.390 --> 18:09.150
So let's call it move speed.

18:09.190 --> 18:14.150
And let's uh by default I'm going to set something like to f something like that.

18:14.150 --> 18:20.030
And third argument we're going to pass our move speed and make sure you multiply this with time dot

18:20.070 --> 18:22.510
delta time to make frame rate independence.

18:22.510 --> 18:24.910
So I'm going to pass our time delta time.

18:24.910 --> 18:27.150
And let's close that up with semicolon.

18:27.150 --> 18:30.310
So what we simply doing inside this update function.

18:30.310 --> 18:33.950
So transform.position basically means the current position of that.

18:33.990 --> 18:38.550
So game object and we're setting equal to Vector2 dot move towards function.

18:38.550 --> 18:40.830
And this vector2 dot move towards function.

18:40.830 --> 18:46.330
Basically as a first argument it's going to take the current position where you are currently right

18:46.330 --> 18:46.770
now.

18:46.770 --> 18:53.010
So we just pass Transform.position, which basically referencing the position we are currently in or

18:53.010 --> 18:56.210
current position, current position of that GameObject.

18:56.330 --> 19:01.850
And the second thing, it's going to take the target position or where you want to move your game object.

19:01.850 --> 19:03.730
So we pass our points.

19:03.730 --> 19:07.930
And inside this square brackets we basically need to pass the index.

19:07.930 --> 19:10.570
And we pass point point index.

19:10.570 --> 19:15.850
And as you can notice in the start of the game we just set our point index to zero.

19:15.850 --> 19:18.610
So this one right over here it's going to be zero.

19:18.610 --> 19:23.290
And we do know that zero basically means the top position or the first point.

19:23.290 --> 19:26.770
So this game object is just going to move over to that point.

19:26.770 --> 19:32.890
So if I move over to my script one more time so just wait you will notice.

19:33.090 --> 19:38.410
So we're gonna move towards to the first position as soon as we're gonna start our game.

19:38.730 --> 19:41.170
As you can notice right over here.

19:41.170 --> 19:44.110
So this point index is zero and zero.

19:44.110 --> 19:46.390
So we're just going over to that position.

19:46.630 --> 19:51.510
Uh, right after, uh, we just accessing the, uh, position of that array.

19:51.550 --> 19:52.790
As you can notice.

19:52.790 --> 19:58.430
And the third argument is just taking the speed with, uh, how much speed we just moving over to that

19:58.430 --> 19:58.950
point.

19:58.950 --> 20:03.070
And now what we're going to do, we're going to press down Ctrl s to save our script.

20:03.070 --> 20:05.110
And now let's move over to unity.

20:05.110 --> 20:11.390
And you will see, as soon as we're gonna start our game, we will able to notice our game object,

20:11.390 --> 20:17.750
or this trap is going to move over to the first point or the top position because the top position index

20:17.750 --> 20:18.470
is zero.

20:18.470 --> 20:19.390
So that's why.

20:19.630 --> 20:25.830
So just wait a moment and you will see, uh, you will see that, uh, we basically just going to move

20:25.830 --> 20:31.830
over to the first point as soon as we're gonna start our game, because the first point index is zero.

20:31.830 --> 20:37.470
And we can notice underneath our show script and the first point index, we can notice it's zero.

20:37.470 --> 20:39.830
And the second point index is one.

20:40.070 --> 20:43.170
So let's suppose you just want to move to the second point.

20:43.170 --> 20:47.650
So as a as a index you need to pass this one.

20:47.650 --> 20:53.690
So it's you you're just going to move over to that point or the bottom position or simply the second

20:53.690 --> 20:54.450
position.

20:54.450 --> 21:00.290
Now our script gets compiled and I'm going to drag my stroke game object a little bit down somewhere

21:00.290 --> 21:01.130
over here.

21:01.370 --> 21:06.890
And if I just go ahead and then click on this play button, you will see as soon as we're gonna, uh,

21:07.250 --> 21:13.610
start our game, these are just going to move over to the top position or the first position because

21:13.650 --> 21:17.450
as in point index, in the start of the game, we just set it to zero.

21:17.450 --> 21:19.930
And zero basically means the first point.

21:19.930 --> 21:22.090
And you're gonna notice that.

21:22.250 --> 21:29.730
And indeed we can notice that it's, uh, going to the first position and it's just sticking right over

21:29.730 --> 21:30.290
here.

21:30.290 --> 21:36.810
So we also need to uh, basically we also need to move over to this second position or this bottom position.

21:36.810 --> 21:41.680
So basically what we have to do, we need to increase our point index by one.

21:41.680 --> 21:46.000
And we do know that if we put a one inside that array point.

21:46.040 --> 21:48.440
Index array point index one.

21:48.440 --> 21:51.920
So it's going to move over to second position or the bottom position.

21:51.920 --> 21:57.320
Because the bottom position we can notice underneath our show script is index is one.

21:57.320 --> 21:58.840
So let's get out of play mode.

21:58.840 --> 22:04.520
So what we're gonna do before we just move over to the first position, we basically want to check the

22:04.520 --> 22:07.360
position between our first point and this.

22:07.520 --> 22:14.720
So game object if the position between our show and the first point or this point with this point is

22:14.720 --> 22:19.080
too much close, then we're just going to increase our point index by one.

22:19.360 --> 22:21.280
And we do know if we increase.

22:21.680 --> 22:25.600
So it's going to move over to the bottom position or the second position.

22:25.600 --> 22:27.040
So let's go over to script.

22:27.040 --> 22:28.680
And we're going to do it over here.

22:28.680 --> 22:31.440
So before we move position we just want to check.

22:31.800 --> 22:35.680
So let's make if condition make first bracket and some curly brackets.

22:35.680 --> 22:39.280
And what we want to check over here we basically want to check.

22:39.280 --> 22:42.700
So we need to use this vector to dot distance function.

22:43.340 --> 22:49.820
And this function it's going to take two position and it's going to take two position.

22:49.820 --> 22:51.980
And it will compare between them.

22:51.980 --> 22:54.700
So we want to check the position with our saw.

22:54.700 --> 22:57.340
So we're going to pass our transform dot position.

22:57.380 --> 23:00.580
It's basically means current position of that object.

23:00.580 --> 23:06.180
And the second thing it's going to take the basically as a second argument it's going to take another

23:06.180 --> 23:08.780
position that we want to compare with.

23:08.780 --> 23:10.740
So we're going to pass our points array.

23:10.940 --> 23:14.860
So we need to pass points array a points array.

23:15.060 --> 23:17.260
And we need to make this square brackets.

23:17.260 --> 23:21.460
And inside this square brackets we basically have to pass our index.

23:21.460 --> 23:24.580
So we're going to pass our point index and point index.

23:24.580 --> 23:26.700
In the start of the game we set zero.

23:26.700 --> 23:28.260
So it's our game object.

23:28.260 --> 23:34.900
Just gonna check the position between our this row and this first position and make sure you access

23:34.900 --> 23:35.740
the position.

23:35.740 --> 23:42.480
So right typing square brackets you need to type this dot position because we need to access the position.

23:42.480 --> 23:48.840
And now if the position between them, if it's lesser than some small number, some smaller number,

23:48.840 --> 23:49.880
we're going to check with.

23:49.920 --> 23:54.040
So we're going to put zero point 1FA pretty smaller number something like that.

23:54.040 --> 23:57.400
So if that is the case basically means our game object.

23:57.400 --> 24:03.320
So we using this Vector2 dot distance function and this Vector2 dot distance function, it's going to

24:03.320 --> 24:06.360
take two position and it will compare between them.

24:06.360 --> 24:12.320
So we just pass as a first argument current position which is transform.position basically means current

24:12.320 --> 24:13.240
position of that.

24:13.280 --> 24:14.280
So game object.

24:14.280 --> 24:21.440
And the second thing we just pass our point index or the top position or where we just moving.

24:21.600 --> 24:25.800
And in this start of the game we do know this point index that's going to be zero.

24:25.800 --> 24:31.680
So in the start of the game this if condition is just going to check the between our this game object

24:31.680 --> 24:33.040
and this first point.

24:33.040 --> 24:38.940
So if it's lesser than some smaller number as you can see we're checking then what we need to do basically

24:38.940 --> 24:41.340
means we just reaches right over here.

24:41.340 --> 24:45.060
So we basically need to increase our point index by one.

24:45.060 --> 24:50.300
And if we increase point index by one then it's going to move over to this point index.

24:50.460 --> 24:50.820
Sorry.

24:50.860 --> 24:54.140
It's going to move over to bottom position or second position.

24:54.140 --> 24:58.340
You can simply say so now let's move over to unit is script.

24:58.340 --> 25:01.900
And now what we have to do we reaches our first point.

25:01.900 --> 25:08.220
You can simply say the the distance between our show and the first point is too much close now.

25:08.220 --> 25:11.980
And now what we need to do we need to increase our point index.

25:11.980 --> 25:15.700
So what we will do, we will use this point index plus plus.

25:15.740 --> 25:18.380
It basically means that we just adding one.

25:18.380 --> 25:20.540
So in this start of the game we set zero.

25:20.540 --> 25:23.340
So plus plus basically means we adding one.

25:23.340 --> 25:24.580
So zero plus one.

25:24.620 --> 25:25.740
It's going to be one.

25:26.180 --> 25:28.620
So this point index it's becoming one.

25:28.620 --> 25:31.900
So this over here right over here it's going to be one.

25:31.900 --> 25:37.620
So so our now the game object just going to move over to our second point.

25:37.680 --> 25:40.360
because this point index is just going to be one.

25:40.400 --> 25:47.360
As soon as our game object reaches top point or the first position, then we increasing our point index

25:47.640 --> 25:48.400
by one.

25:48.400 --> 25:51.240
So the point index right over here becomes one.

25:51.280 --> 25:55.520
Means our game object just going to move over to our bottom position.

25:55.520 --> 25:58.360
Or you can simply say the second position.

25:58.360 --> 26:01.280
And now we're going to press down Ctrl S to save our script.

26:01.280 --> 26:02.920
And let's move over to unity.

26:03.120 --> 26:09.480
So as soon as our game object just just going to reach our top position, it's going to move over to

26:09.520 --> 26:10.440
second position.

26:10.440 --> 26:16.120
Because the we checking the distance between our shore and the first point, if it's lesser than with

26:16.120 --> 26:20.520
some smaller number, then we just increasing our point index by one.

26:20.520 --> 26:26.000
And we do know if we increase by one that means point index becoming one and one.

26:26.000 --> 26:28.240
We do know that is the second position.

26:28.240 --> 26:31.040
Or you can simply say this bottom position.

26:31.040 --> 26:33.680
So just wait a little moment and it's done now.

26:33.680 --> 26:36.040
So I'm going to move it somewhere over here.

26:36.040 --> 26:37.860
And let's click on this play button.

26:37.860 --> 26:43.460
And you will see as soon as this game object and the first point, uh, first point position, if the

26:43.460 --> 26:47.220
distance between is too much close, then we increasing.

26:47.620 --> 26:52.780
Then we increasing our point index means it's gonna move over to the second position.

26:52.780 --> 26:55.620
Or you can simply say to the bottom position.

26:55.620 --> 26:57.140
So just wait a moment.

26:57.140 --> 27:00.820
And indeed we can see it just reaching the second position.

27:00.820 --> 27:07.380
And now it's stuck at second position or this bottom position because we just keep increasing our point

27:07.420 --> 27:08.060
index.

27:08.060 --> 27:09.780
So we're gonna get out of play mode.

27:09.780 --> 27:15.620
So now what we're gonna do if this short game object is, uh, something like over here with the second

27:15.620 --> 27:21.140
position, uh, or the bottom position, you can simply say if the distance between is now too much

27:21.140 --> 27:23.020
close with the second position.

27:23.020 --> 27:26.620
Then again, we're gonna set back our point index to zero.

27:26.620 --> 27:33.060
So this, uh, so just gonna move over to top position if we set back, uh, point index to zero, because

27:33.100 --> 27:35.300
zero basically means the top position.

27:35.300 --> 27:37.650
Or you can simply say the first position.

27:37.650 --> 27:41.050
So what we will do for that, we're going to move over to our script.

27:41.210 --> 27:42.970
And over here we're going to check.

27:42.970 --> 27:45.930
So let's go to top of our class and we will check.

27:45.930 --> 27:47.570
So we're going to use this if condition.

27:47.570 --> 27:50.170
Let's make first bracket and some curly brackets.

27:50.170 --> 27:52.170
And what we want to check over here.

27:52.170 --> 27:54.730
We basically want to check uh sorry.

27:55.610 --> 28:03.650
We basically want to check if our point index if it's equals equals to points uh points dot length.

28:04.010 --> 28:07.050
Points dot length basically means how many points we have.

28:07.290 --> 28:13.330
So point if the point index is equals equals to point dot length basically means how many points we

28:13.330 --> 28:13.730
have.

28:13.930 --> 28:17.370
So we have we can notice we have one and two.

28:17.530 --> 28:22.170
So this point index points dot length right over here it's going to be two.

28:22.370 --> 28:24.530
And if the point index is one.

28:24.930 --> 28:31.650
So as soon as it reaches our point basically means we just uh over here somewhere over here.

28:31.650 --> 28:36.310
So we're checking as you can see we're checking if our point index is equals.

28:36.350 --> 28:38.110
Equals to points dot length.

28:38.270 --> 28:41.590
Points dot length basically means how many points we have.

28:42.110 --> 28:45.070
Means our game object is right over here.

28:45.070 --> 28:46.390
So now what we need to do.

28:46.430 --> 28:49.190
We need to set back our point index to zero.

28:49.230 --> 28:50.510
Because we are increasing.

28:50.510 --> 28:55.310
And we are checking if the point index is equals equals to our points dot length.

28:55.350 --> 29:00.630
So if that is the case then we're going to set back this point index to zero once again.

29:00.630 --> 29:07.310
And we do know if we set back to zero it's going to move over to our top position or the first position.

29:07.310 --> 29:10.110
So we're going to set our point index back to.

29:10.150 --> 29:13.190
So let's set our point index equal to zero.

29:13.190 --> 29:15.230
And let's close that up with semicolon.

29:15.230 --> 29:17.950
And we're going to press down Ctrl s to save our script.

29:17.950 --> 29:19.830
And now let's move over to unity.

29:19.830 --> 29:25.430
So as soon as this game object just going to check with second position or the bottom position.

29:25.430 --> 29:28.470
And we do know once it's just going to reach bottom position.

29:28.470 --> 29:30.830
So the index point index is going to be one.

29:30.830 --> 29:34.210
And we're checking if the point index is equals Equals.

29:34.210 --> 29:34.370
To.

29:34.410 --> 29:34.530
To.

29:34.570 --> 29:34.730
Oh.

29:34.770 --> 29:35.410
Or that.

29:35.450 --> 29:36.890
How many points we have.

29:36.930 --> 29:40.290
Then we again setting back our point index to zero.

29:40.290 --> 29:44.330
And we do know that the point index zero basically means the top position.

29:44.330 --> 29:47.970
And point index one basically means the bottom position.

29:48.090 --> 29:54.250
So we will able to notice that this game object just going to move between these two points, once it's

29:54.250 --> 29:59.930
going to reach the bottom position, then it's again going to move over to top position because we changing

29:59.930 --> 30:01.130
the point index.

30:01.290 --> 30:05.170
So let's click on this play button in the top in order to play our game.

30:05.170 --> 30:08.930
And we're gonna take a look on that on this.

30:08.930 --> 30:15.650
So as soon as this point sorry this game object just going to check with the second position or the

30:15.650 --> 30:19.490
bottom one is going to move over to the first point once again.

30:19.770 --> 30:23.770
And we can notice that it's moving to the first point and second point.

30:23.770 --> 30:30.810
And as soon as it's reaching or sorry reaching to the second point, we can see it just moving over

30:30.810 --> 30:31.970
to the first point.

30:31.970 --> 30:33.790
But we getting an array?

30:34.150 --> 30:38.790
Sorry, we're getting an error in our console tab that says.

30:38.830 --> 30:42.430
Index was outside the bounds of the array.

30:42.590 --> 30:44.950
So we basically need to get out of play mode.

30:44.950 --> 30:47.310
And we need to move over to our script.

30:47.310 --> 30:53.150
And we need to put this line of code right over here underneath, uh, underneath everything.

30:53.270 --> 30:59.350
Uh, so we can just move, we can select like this and we can hold down alt or alt key on our keyboard,

30:59.350 --> 31:05.310
and we can use our up or down arrow key in order to move this line of code, as you can notice.

31:05.430 --> 31:07.750
So I'm gonna move it somewhere over here.

31:07.750 --> 31:09.110
And now that's fine.

31:09.110 --> 31:14.550
And make sure you press down Ctrl s on your keyboard in order to save your script one more time.

31:14.870 --> 31:16.070
And it's gonna save.

31:16.310 --> 31:18.270
So I hope you get the idea.

31:18.310 --> 31:23.150
Now I'm gonna press down one more time to control S, and let's move over to unity.

31:23.150 --> 31:24.870
So it's gonna be fine by now.

31:25.190 --> 31:28.790
We're not gonna see any error in our console tab.

31:29.150 --> 31:35.170
I hope you get the idea that how you can just move a game object between two points and you can create

31:35.170 --> 31:36.850
as many points you want.

31:36.890 --> 31:39.610
So you can just duplicate this second point.

31:39.610 --> 31:46.370
And you you need to make sure that you also, uh, also select the third point and then drag it over

31:46.370 --> 31:53.330
to this points array, or else you're gonna get some error or you not gonna move over to the third position.

31:53.330 --> 31:54.250
So that's why.

31:54.290 --> 31:55.770
And I'm gonna show you that.

31:56.210 --> 31:58.730
So let it first compile it.

31:59.570 --> 32:04.930
And let's click on this play button in the top in the in order to play our game.

32:05.170 --> 32:06.970
And let's take a look on this.

32:09.690 --> 32:11.850
So just wait wait a moment.

32:11.850 --> 32:17.370
And by now we should not see any error messages.

32:17.370 --> 32:19.930
Just going to pop up underneath our console tab.

32:20.250 --> 32:21.930
So I'm going to clear it first.

32:22.130 --> 32:27.250
As you can notice in our console tab we not getting any error messages.

32:27.250 --> 32:30.490
Let's suppose we want to move this game object.

32:30.610 --> 32:31.870
Uh three points.

32:31.870 --> 32:33.910
Something over here as well.

32:33.910 --> 32:35.390
So we're gonna get out of play mode.

32:35.390 --> 32:35.870
For that.

32:35.870 --> 32:38.190
We need to create one more point.

32:38.350 --> 32:40.350
Or you can simply say position.

32:40.350 --> 32:42.990
So we will select the second or the first position.

32:42.990 --> 32:45.390
And let's press down Ctrl D to duplicate.

32:45.750 --> 32:46.590
Uh sorry.

32:46.630 --> 32:49.110
And we're going to move it somewhere over here.

32:49.110 --> 32:51.510
And let's call this point to something like three.

32:51.670 --> 32:52.910
So let's call it three.

32:53.070 --> 32:58.870
And now what we have to do we need to put this three point, uh, basically the third point into our

32:58.910 --> 33:01.870
array or else we're not gonna move at all.

33:01.870 --> 33:03.590
So to the third point.

33:03.590 --> 33:06.270
So I'm going to select my sock object in the hierarchy.

33:06.310 --> 33:08.790
Let's go over to our script in the Inspector.

33:09.030 --> 33:14.630
Uh, so we can see we only have the first point and the second point and we don't have the third point

33:14.830 --> 33:15.470
yet.

33:15.470 --> 33:19.590
So we will select the third point and let's drag it over to this point array.

33:19.630 --> 33:26.350
Now we can see uh, the third point index is now two, index is two, second point index is one.

33:26.350 --> 33:29.870
And the first point index is zero basically means this.

33:29.910 --> 33:35.780
Uh short game object just going to move around between these points, because we're just checking the

33:35.780 --> 33:37.860
distance between our points.

33:37.860 --> 33:42.940
And if that gets closer, then we just are increasing our point index.

33:42.940 --> 33:48.180
And once it reaches the final position, then again we're setting back point index to zero.

33:48.300 --> 33:52.660
So that's why this game object is just going to move over to first point one more time.

33:52.900 --> 33:57.580
So let's click on this play button in the top in order to take a look on this.

33:57.580 --> 34:03.660
And you can increase the speed as well by just going over to your your source script.

34:03.660 --> 34:06.660
And you can just play around with the move speed.

34:06.660 --> 34:10.140
So just wait a moment and we will able to notice that.

34:10.460 --> 34:16.900
So this game object just gonna move between these three points because we just increase and we will

34:16.940 --> 34:17.700
able to notice.

34:17.700 --> 34:19.540
So it's move it over here.

34:19.540 --> 34:23.620
Then here as you can notice indeed it's moving to the third point.

34:23.900 --> 34:28.460
And we basically need to move our show a little bit something over here.

34:28.660 --> 34:30.240
And we can notice that.

34:30.240 --> 34:32.000
So I'm going to get out of play mode.

34:32.000 --> 34:39.280
And what I'm going to do I'm going to move the third point somewhere over here to just to just make

34:39.320 --> 34:39.840
sure.

34:39.840 --> 34:44.520
So I'm going to select my third point and let's move it somewhere around here.

34:44.840 --> 34:48.640
And let's press down control S in order to save our project.

34:49.000 --> 34:50.760
And I'm going to move this here.

34:50.760 --> 34:55.320
So now let's click on this play button in the top in order to play our game.

34:55.480 --> 34:59.480
And we will be able to notice our game game object.

34:59.520 --> 35:02.960
Just going to move between these three points and one.

35:03.280 --> 35:09.160
Once it's gonna reach the final position or the third point, you can simply say then again we're setting

35:09.160 --> 35:12.760
back point index to zero basically means our show game object.

35:12.760 --> 35:17.000
Just gonna move over to our first point right away.

35:17.040 --> 35:23.480
As you can see, indeed the show game object just moving between these three points and you can create

35:23.480 --> 35:28.040
as many points you want and make sure you track those points into your array.

35:28.040 --> 35:33.060
So you're gonna have the position, and after that you can just move your game object.

35:33.060 --> 35:34.300
So I hope you get the idea.

35:34.300 --> 35:35.940
So I'm gonna get out of play mode.

35:35.940 --> 35:41.820
And also make sure you make this game object a prefab so you will have the copy of it.

35:41.820 --> 35:45.580
So I'm going to head over to my project tab then assets folder.

35:45.580 --> 35:49.340
So just wait a little bit assets folder and then prefabs folder.

35:49.540 --> 35:52.260
And let's select the GameObject in the hierarchy.

35:52.260 --> 35:57.660
And let's drag it inside this prefabs folder in order to turn it into a prefab.

35:57.660 --> 36:00.820
And now as you can notice, we just turn it into a prefab.

36:00.820 --> 36:07.220
Basically, it's turned out blue means we just made it prefab and we can just click on it at this point

36:07.220 --> 36:10.340
scheme object in order to collapse all of our points.

36:10.340 --> 36:15.940
So that's why we just created an empty parent game object first and into that game object, we just

36:15.940 --> 36:21.980
created those tile game object in order to make our hierarchy a little bit clean or the project, you

36:21.980 --> 36:27.740
can simply say, and we're going to press down one more time, Ctrl s on our keyboard in order to save

36:27.740 --> 36:28.660
our project.
