WEBVTT

00:00.080 --> 00:02.280
Let's create our second anime.

00:02.320 --> 00:05.360
For now, I'm just gonna disable this first anime.

00:05.360 --> 00:10.840
So I will select my anime one game object in the hierarchy and let's go to Inspector.

00:10.840 --> 00:13.280
You can just uncheck in order to disable.

00:13.440 --> 00:16.920
And if you just want to enable then you can just check there.

00:17.120 --> 00:19.200
But I'm gonna disable it for now.

00:19.200 --> 00:23.120
So I'm gonna uncheck that and let's create the second anime.

00:23.160 --> 00:31.440
To do so let's move over to project tab assets and then sprites folder I have A3 folder where I have

00:31.440 --> 00:32.280
the second anime.

00:32.280 --> 00:33.560
So I'm going to choose that.

00:33.880 --> 00:37.400
So I have a skeleton sprite as you can see.

00:37.400 --> 00:40.680
So I'm going to select all of this sprite by holding down shift.

00:40.680 --> 00:42.040
Let's go to Inspector.

00:42.120 --> 00:47.960
And I'm going to make this pixel per unit to something like 16 and filter mode to point filter to just

00:47.960 --> 00:49.480
get rid of blurry.

00:49.480 --> 00:55.600
And after doing all of this thing click on this apply and we're going to find the ideal sprite of this

00:55.600 --> 00:56.760
skeleton anime.

00:57.040 --> 01:00.440
So let's select the ideal sprite sheet from.

01:01.320 --> 01:03.160
Let's choose the ideal one.

01:04.720 --> 01:05.840
So work.

01:05.880 --> 01:07.200
And this one is ideal.

01:07.200 --> 01:08.560
So let's select that.

01:08.560 --> 01:12.280
Go over to Inspector and let's click on this open Sprite editor.

01:12.280 --> 01:15.200
So we can see we have multiple enemies.

01:15.200 --> 01:17.240
So we need to split individually.

01:17.240 --> 01:19.120
So let's go to Sprite Editor tab.

01:19.120 --> 01:20.680
Let's click on this slice.

01:20.680 --> 01:22.720
And we're going to select Grid by Cell count.

01:22.720 --> 01:25.720
And let's count how many columns and rows it has.

01:25.720 --> 01:28.960
So 36678.

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

01:31.760 --> 01:33.840
Let's click on slice Apply.

01:34.240 --> 01:36.360
And we're also going to find the attack one.

01:36.360 --> 01:39.440
So I have this sprite sheet which is the attack one.

01:40.080 --> 01:43.480
Let's slice as well this one.

01:43.480 --> 01:44.720
So we need to count first.

01:44.720 --> 01:49.960
So 489 ten I guess ten columns.

01:49.960 --> 01:53.400
So we're going to put around ten columns and one row.

01:53.440 --> 01:56.680
Let's click on this slice and then click on apply.

01:57.480 --> 02:02.120
And what we need to do now let's select the game view once again over here.

02:02.400 --> 02:04.270
And let's select the ideal sprite.

02:05.350 --> 02:07.750
So I'm going to choose the ideal one.

02:08.550 --> 02:10.670
So we have it here.

02:11.070 --> 02:15.110
So let's click on this arrow in order to see the individual sprites.

02:15.230 --> 02:17.070
And I'm going to select my first one.

02:17.070 --> 02:20.990
And let's drag it over to this scene view or into the hierarchy.

02:21.390 --> 02:27.030
And what I want to do I just want to make it a little bit bigger basically this anime.

02:27.070 --> 02:32.150
So I'm going to make the pixel per unit a bigger number.

02:32.150 --> 02:33.910
So I'm going to select all of them.

02:34.070 --> 02:37.430
And I'm going to make this pixel per unit something like 12.

02:37.750 --> 02:39.830
And now let's click on this apply.

02:40.590 --> 02:43.670
And now we can see it's a little bit bigger.

02:43.670 --> 02:44.230
So I.

02:44.670 --> 02:47.270
I'm gonna name it to something like anime two.

02:47.750 --> 02:50.430
Let's call it anime two.

02:50.830 --> 02:53.990
And we also need to flip this anime to the left direction.

02:53.990 --> 02:59.510
To do so let's go to Sprite Renderer component, and we're going to check this flip in the x axis or

02:59.550 --> 03:00.630
horizontally.

03:01.110 --> 03:03.710
And let's add some components to this anime.

03:03.710 --> 03:04.350
Game object.

03:04.350 --> 03:05.630
Anime two game object.

03:05.710 --> 03:10.110
Firstly, we're going to add a box collider 2D for collision detection.

03:10.110 --> 03:12.190
Let's add the rigid body first.

03:12.190 --> 03:17.670
So let's click on this add component and we're going to add the rigid body 2D for gravity.

03:17.870 --> 03:22.510
And I'm going to increase my gravity something around three collision detection.

03:22.510 --> 03:27.270
We're going to choose continuous and make sure you just freeze the rotation in the z axis.

03:27.270 --> 03:30.110
Or it's going to rotate like uh weirdly.

03:30.110 --> 03:30.990
So that's why.

03:31.270 --> 03:34.710
And now let's add a box collider 2D for collision detection.

03:34.710 --> 03:36.710
So let's click on this add component.

03:36.710 --> 03:39.070
And we're gonna add a box Collider 2D.

03:39.230 --> 03:46.950
And let's add adjust the collider as the size of our anime two game object or as the size of our skeleton.

03:46.950 --> 03:48.870
So let's click on this Edit Collider.

03:48.870 --> 03:54.670
And we're going to edit the collider as the size of our, uh, this skeleton game object.

03:54.990 --> 03:56.350
And now it's fine.

03:57.190 --> 04:01.550
And we also need to create the animation, uh, animation as well.

04:02.350 --> 04:04.590
So uh, we're going to create that.

04:04.590 --> 04:11.590
But before it, let's create a script in order to attack on this player game object.

04:11.590 --> 04:12.830
So let's do that.

04:12.830 --> 04:17.830
So for that we're going to move over to project app, then Assets folder and then head over to this

04:17.830 --> 04:18.710
script folder.

04:18.710 --> 04:22.230
Let's right click there create and then Monobehaviour script.

04:22.230 --> 04:25.350
And you can name that script to something like animator.

04:25.390 --> 04:29.790
I already have created a anime script, as you can see over here.

04:29.790 --> 04:34.310
So we need to attach this script to our anime to GameObject in the hierarchy.

04:34.430 --> 04:39.110
So let's select the animator GameObject in the hierarchy, and let's select this script and drag it

04:39.110 --> 04:42.510
over to this Add Component section in the Inspector.

04:42.510 --> 04:45.150
And we're gonna open that up by quickly.

04:45.510 --> 04:52.910
And what we're gonna do now, uh, firstly we need a reference to our player game object uh, or player

04:52.950 --> 04:54.270
transform means position.

04:54.270 --> 04:57.190
So we can just keep track of where player is.

04:57.230 --> 05:00.870
And also we're gonna define a attack range in this enemy script.

05:00.870 --> 05:01.910
Enemy two script.

05:02.190 --> 05:08.140
Uh, in order to attack on this player game object, and if this player just comes in attack range,

05:08.180 --> 05:12.300
then then this army need to attack on our player game object.

05:12.300 --> 05:13.820
So basically that is the thing.

05:13.820 --> 05:18.140
So let's open up our animator script and let's go to top of our class.

05:18.140 --> 05:20.220
And we need to gather those variable.

05:20.260 --> 05:24.060
First thing we need our player transform means player position.

05:24.060 --> 05:27.140
So let's make a public transform.

05:27.140 --> 05:31.980
You can simply say this transform is responsible for position and we have to name it.

05:31.980 --> 05:34.340
So we can simply call it player position.

05:34.340 --> 05:36.340
Or I'm going to call it simply player.

05:36.500 --> 05:38.900
And the second thing we need a attack range.

05:38.900 --> 05:40.780
So let's define that as well.

05:40.780 --> 05:43.460
So I'm going to make another public float.

05:43.460 --> 05:48.700
And we can call this one to something like attack radius or attack range as well.

05:48.700 --> 05:51.020
So I'm going to call it attack range.

05:51.140 --> 05:55.540
And by default I'm going to set around something like four F or four unit.

05:56.180 --> 05:59.860
And we need a more things.

06:00.100 --> 06:07.100
Uh, but before we do, let's save our script and then move over to unity because we need to assign

06:07.100 --> 06:08.940
those variables one by one.

06:08.940 --> 06:11.980
Firstly, we're going to able to see our player transform.

06:11.980 --> 06:14.940
So we need to drag the player game object in that slot.

06:14.940 --> 06:17.740
Basically we need the player transform.

06:17.740 --> 06:20.620
Or you can simply say the player position.

06:20.620 --> 06:22.100
So just wait for to compile.

06:22.100 --> 06:26.180
And once it's done we need to drag all of those things.

06:26.620 --> 06:35.780
So now as soon as player sorry animator script gets compiled, we can see player and it says transform.

06:35.780 --> 06:39.740
So let's select the player game object in the hierarchy and drag it right there.

06:39.780 --> 06:41.740
Now we can see player transform.

06:41.740 --> 06:44.300
We have the reference means player position.

06:44.300 --> 06:46.060
So let's open up our script.

06:46.420 --> 06:52.980
So what we basically want to do we're going to create a circle around this uh, around uh, this uh,

06:52.980 --> 06:57.140
skeleton game object or this enemy two game object.

06:57.140 --> 07:03.940
And if this player game object comes in or just collide with that circle, then this enemy game object,

07:03.980 --> 07:08.810
uh, this enemy two game object needs to attack on our player game object.

07:08.810 --> 07:09.730
So we're gonna do that.

07:09.730 --> 07:16.450
We're going to create a circle around this enemy two or this enemy, uh, sorry, skeleton game object.

07:16.450 --> 07:22.410
And if this player game object get inside, then this enemy two game object or this skeleton need to

07:22.410 --> 07:24.050
attack on our player.

07:24.370 --> 07:25.570
So we're gonna do that.

07:25.570 --> 07:28.690
But before we do, let's make sure you just, uh.

07:28.810 --> 07:32.610
And make that this enemy two as well as a prefab.

07:32.610 --> 07:34.130
So we're gonna have the copy.

07:34.130 --> 07:39.610
So let's select the animator GameObject in the hierarchy, and let's drag it over to this prefabs folder.

07:40.210 --> 07:42.610
And now we just turn it into a prefab.

07:42.970 --> 07:47.490
And let's open up the script by now by double clicking on it.

07:47.490 --> 07:50.930
So we're gonna move over to this update function.

07:50.930 --> 07:54.690
And we do know that update function runs every single frame.

07:54.690 --> 07:56.930
So every single frame we're going to keep track of.

07:56.970 --> 07:58.570
So we're going to create the circle.

07:58.730 --> 08:05.730
And in order to create the circle we need to use this physics 2D dot overlap circle overlap circle.

08:06.050 --> 08:11.770
And this over here as a first argument, it's going to take the position from where you want to create

08:11.770 --> 08:12.450
the circle.

08:12.610 --> 08:18.290
So this physics 2D overlap circle will just create the circle around our enemy game object.

08:18.290 --> 08:20.530
So we just want to create the circle.

08:20.530 --> 08:23.370
And on this enemy GameObject center position.

08:23.370 --> 08:28.330
So as a first argument it's going to take the position from where we want to create.

08:28.330 --> 08:34.330
So we're going to pass this Transform.position Transform.position basically means current position or

08:34.330 --> 08:37.290
center position our enemy game object.

08:37.290 --> 08:42.770
And the second thing comma, it's going to take the radius with how much radius you just want to create

08:42.770 --> 08:43.490
the circle.

08:43.490 --> 08:48.490
So we're going to create the circle around this much radius or this much of attack range.

08:48.530 --> 08:50.370
As you can see we created.

08:50.370 --> 08:55.650
So we're going to pass this as a second argument which is attack range attack range.

08:55.650 --> 08:57.250
And by default we set four.

08:57.250 --> 08:59.490
So the circle will be drawn from this.

08:59.530 --> 09:05.850
Or just going to create from this enemy GameObject center position with this matchup attack range radius

09:05.850 --> 09:07.290
which is for unit.

09:07.890 --> 09:14.850
And the third argument we need the layer mask or which game object basically we want to deal with.

09:14.890 --> 09:17.610
So we'll deal with this player game object.

09:17.650 --> 09:20.730
And we're gonna only check for this player game object.

09:20.730 --> 09:27.050
If this player game object comes in attack range of this enemy game object, you can simply say then

09:27.050 --> 09:31.050
this enemy game object need to attack on this player game object.

09:31.050 --> 09:34.050
So we're gonna only check gonna check for this player.

09:34.050 --> 09:35.650
So we need the layer mask.

09:35.650 --> 09:37.450
So let's go to top of our class.

09:37.450 --> 09:40.170
And let's define a layer mask as well.

09:40.210 --> 09:43.250
Basically which game object we simply want to target.

09:43.250 --> 09:46.450
So let's create a public that will be layer mask.

09:46.770 --> 09:51.050
And we can call this one to something like target layer or attack layer.

09:51.090 --> 09:53.970
I'm going to call it something like Target Layer.

09:55.170 --> 09:57.010
And let's close that up with semicolon.

09:57.010 --> 10:00.650
As a third argument over here we're going to pass the target layer.

10:00.890 --> 10:03.090
And let's close that up with semicolon.

10:03.450 --> 10:05.210
So now what we have to do.

10:05.250 --> 10:06.970
Let's save our script first.

10:06.970 --> 10:12.720
And let's move to unity because we need to assign those variable by one by one.

10:12.720 --> 10:17.080
So as a layer mask or target layer we created, we can choose this layer.

10:17.080 --> 10:22.520
But before you choose player make sure you assign your player game object as a player layer.

10:23.840 --> 10:26.000
So now we gonna able to see.

10:26.800 --> 10:32.880
As you can see, as soon as enemy two script gets compile target layer and it says nothing.

10:32.880 --> 10:34.080
So we're going to choose the player.

10:34.080 --> 10:39.480
But before you do, make sure you select your player game object in the hierarchy and in the inspector

10:39.480 --> 10:41.880
top right you can see layer and it will be default.

10:41.880 --> 10:44.960
So just click there and then click on this add layer.

10:44.960 --> 10:47.480
And you have to name the layer what you want to name it.

10:47.480 --> 10:51.400
So you can name it something like player and make sure you just go.

10:51.400 --> 10:57.080
Also go back to that game object one more time, then go over to Inspector and the layer.

10:57.080 --> 10:58.000
It will be default.

10:58.000 --> 11:02.240
So you can just select the the which one you recently created.

11:02.240 --> 11:06.080
So you just assign with that and it's going to be fine.

11:06.240 --> 11:10.400
And now what we're going to do as a target layer and it says nothing.

11:10.400 --> 11:13.080
So I only want to check for this player game object.

11:13.080 --> 11:15.400
So I'm going to choose the player over here.

11:15.400 --> 11:18.400
Or I only want to damage this player game object.

11:18.400 --> 11:22.680
So that's why as a target layer or layer pass, we have chosen this player.

11:22.720 --> 11:25.120
You can choose multiple layers as well.

11:25.280 --> 11:30.840
Or if you have, if you just want to damage multiple things, then you can choose that.

11:31.360 --> 11:35.280
But I'm going to choose this player only for now and let's go to script.

11:36.480 --> 11:42.040
So this just going to create the circle around our enemy position, center position with this much of

11:42.040 --> 11:45.360
radius which is attack range and target layer.

11:45.360 --> 11:49.440
So as a target layer we already have chosen our player game object.

11:49.440 --> 11:53.200
So the circle only going to check for our player game object.

11:53.200 --> 11:59.920
So this over here it's going to return us to true or false depending upon if this player game object

11:59.920 --> 12:05.880
really collide with that circle, then this function over here, it's going to give us a true value

12:06.000 --> 12:08.520
as it will give us a false value.

12:08.520 --> 12:15.160
So what we will do, we're going to store the result into a collider 2D because this is gonna work like

12:15.160 --> 12:16.000
as a collision.

12:16.000 --> 12:19.920
So we need to store the result into a collider 2D variable.

12:19.920 --> 12:21.200
So let's put it over here.

12:21.200 --> 12:23.840
So we're going to create a collider 2D variable.

12:23.840 --> 12:26.760
And we can call this one to something like call info.

12:26.800 --> 12:30.440
Or you can simply say call information collision information.

12:30.440 --> 12:32.400
And let's set equal to this.

12:32.400 --> 12:38.360
So this this can be true or false depending upon the circle is really colliding with the player game

12:38.400 --> 12:39.080
object or not.

12:39.120 --> 12:40.680
If it's then it's going to be true.

12:40.880 --> 12:47.120
So we are storing that result into this call info means this call info is going to be true right away

12:47.120 --> 12:50.960
if the circle is really colliding with that player game object.

12:50.960 --> 12:53.360
So we're going to check in the next line.

12:53.360 --> 12:58.960
We will check if and make first bracket some curly brackets and what we want to check over here.

12:59.000 --> 13:00.440
We're going to check this call.

13:00.440 --> 13:02.920
Info is equals equals to true.

13:03.080 --> 13:04.960
Or you can just leave it like this.

13:05.000 --> 13:11.040
It's also basically means true means our player game object really are colliding with the enemy game

13:11.080 --> 13:12.230
object circle.

13:12.510 --> 13:14.830
So what it's need to do now?

13:14.830 --> 13:19.990
This anime game object need to, uh, attack on this player game object by now.

13:20.630 --> 13:21.190
Uh, so.

13:21.190 --> 13:23.230
So for now, let's print out a message.

13:23.270 --> 13:25.350
Uh, if it's perfectly working or not.

13:25.390 --> 13:29.270
So we're going to type debug dot log in order to print out a message.

13:29.470 --> 13:34.750
And over here what we're going to do, we're going to use this call information parameter in order to

13:34.790 --> 13:37.430
extract info what we collided with.

13:37.470 --> 13:40.070
So we storing all of the information.

13:40.070 --> 13:44.030
Basically the result into this call info call info parameter.

13:44.150 --> 13:49.670
And we can use this parameter in order to extract all of the things that we want to, uh, do.

13:49.670 --> 13:51.870
Something like we can extract info.

13:51.910 --> 13:57.910
The name of the game object the circle collided with the tag of the game object, or any component that

13:57.910 --> 13:59.230
we looking for.

13:59.390 --> 14:03.510
So we're going to print out the name of the game object the circle collided with.

14:03.510 --> 14:09.670
So we're going to use we're going to take this call info parameter in order to extract information.

14:09.950 --> 14:17.190
So we're going to go to call info and then dot GameObject, dot name and top of that I'm going to add

14:17.190 --> 14:18.070
a custom message.

14:18.070 --> 14:21.390
So let's use this plus icon and some quotation.

14:21.390 --> 14:23.430
And I'm going to say something like uh.

14:25.590 --> 14:31.390
The takes damage or in attack range.

14:32.030 --> 14:34.190
And let's close that up with semicolon.

14:34.190 --> 14:40.950
So what we basically have done over here, we're just using this call info parameter in order to extract

14:40.990 --> 14:43.470
info, uh extract the name.

14:43.470 --> 14:48.510
So call info dot GameObject basically means the GameObject the circle collided with.

14:48.510 --> 14:51.790
So the circle will be created from this enemy GameObject.

14:51.950 --> 14:56.750
And if this player GameObject collide with that circle, then what we're doing, we just using that

14:56.790 --> 15:02.790
call info parameter and we just extracting information about the GameObject we collided with.

15:02.790 --> 15:06.310
So the circle definitely gonna collide with this player game object.

15:06.310 --> 15:09.430
So what we're doing we're just going over to this player game object.

15:09.550 --> 15:14.940
And then we just accessing the name so we can see in the inspector the name is player.

15:14.940 --> 15:21.500
So this call info dot GameObject dot name basically means uh, it will be a player, uh, the name and

15:21.500 --> 15:25.380
top of that we just added a custom message says in attack range.

15:25.380 --> 15:28.500
So this should be a player in attack range.

15:28.500 --> 15:32.020
So this message just gonna pop up underneath our console tab.

15:32.020 --> 15:34.780
So I'm going to press down Ctrl S to save our script.

15:34.820 --> 15:36.900
And let's move to unity by now.

15:36.900 --> 15:40.660
And we need to select our console in order to see that.

15:44.820 --> 15:46.340
So just wait for to compile.

15:46.820 --> 15:50.460
Uh, but, uh, the problem is that we're not able to see our circle.

15:50.460 --> 15:58.380
It would be nice if we able to see our circle as well, so we can just, uh, get a visual appealing.

15:58.380 --> 16:01.380
So let's open up our script one more time.

16:01.580 --> 16:07.540
And we do know we need to use a function on draw gizmo selected in order to draw something.

16:07.540 --> 16:16.700
So we're going to do it over here on sorry on draw gizmo more selected and make sure users typing as

16:16.700 --> 16:17.660
I did over here.

16:17.700 --> 16:20.300
Else it not gonna be, uh, not gonna work.

16:20.300 --> 16:21.860
Because this is unity.

16:21.860 --> 16:25.860
Callback function means it's gonna call by unity automatically.

16:25.860 --> 16:28.900
You don't need to call this function anywhere else.

16:29.140 --> 16:37.060
So in order to, uh, draw a circle, we need to use this gizmos dot draw where sphere function.

16:37.300 --> 16:42.500
And this over here as a first argument, it's going to take the position from where we want to draw.

16:42.500 --> 16:47.860
So we're going to draw the transform dot position or basically center position of our enemy.

16:47.900 --> 16:50.420
Second thing comma it's going to take the radius.

16:50.420 --> 16:53.900
And we're going to draw the circle around this much of attack range.

16:53.940 --> 16:57.260
As you can see with this much of attack range radius.

16:57.260 --> 17:03.340
So as the second argument we're going to pass this attack range attack range uh as a radius.

17:03.460 --> 17:05.780
And then we're going to close that up with semicolon.

17:05.780 --> 17:11.820
And if you want to choose a different color then you can just go up and you can choose the color as

17:11.820 --> 17:14.380
well before you draw the circle.

17:14.380 --> 17:16.500
So we're going to use this gizmos.

17:16.700 --> 17:17.180
Sorry.

17:18.140 --> 17:19.300
Uh, gizmos.

17:19.780 --> 17:20.740
Gizmos.

17:20.780 --> 17:23.140
Dot dot color.

17:23.140 --> 17:27.420
And you can set equal to any color that you would like to go with.

17:27.420 --> 17:30.380
So I'm going to say something like color dot yellow.

17:30.420 --> 17:33.180
I will use in order to draw my circle.

17:33.180 --> 17:35.540
And let's close that up with semicolon.

17:35.540 --> 17:38.980
And let's press down control S in order to save our script.

17:39.020 --> 17:40.700
And let's move to unity.

17:40.700 --> 17:46.460
So we will see as soon as the script is going to get compiled, we will see the circle will be drawn

17:46.460 --> 17:51.060
from this enemy GameObject center position, uh, from this enemy two.

17:51.100 --> 17:52.020
So just wait.

17:53.940 --> 17:56.580
And uh, if we select our enemy two.

17:56.620 --> 18:03.260
As you can see now, the circle has been drawn, so we can just increase the radius of this circle as

18:03.260 --> 18:03.580
well.

18:03.580 --> 18:10.340
So I'm going to make the attack range something like 5.5 something like that something around that.

18:10.380 --> 18:14.260
And let's go to Overrides and Inspector let's click on this apply all.

18:14.620 --> 18:20.690
And I'm going to move this uh, anime game object a little bit down somewhere over here, and I'm going

18:20.730 --> 18:25.890
to select my console tab, and let's click on this play button in the top in order to see the message

18:25.890 --> 18:26.810
in the console.

18:27.530 --> 18:28.530
So just wait.

18:28.530 --> 18:34.450
And once it's done, we are ready to go inside the circle of this anime to game object.

18:34.450 --> 18:38.610
And as soon as we're gonna collide, that message should pop up right away.

18:38.610 --> 18:41.130
So let's, uh, have a look on this.

18:43.810 --> 18:49.610
As you can see, as soon as we get inside of that circle, a message just getting pop up in the console

18:49.610 --> 18:51.690
says player in attack range.

18:51.690 --> 18:53.370
So let's get out of play mode.

18:53.370 --> 19:00.610
And instead of, uh, basically printing out that we need to basically this anime game enemy to game

19:00.650 --> 19:03.130
object need to play the attack animation.

19:03.650 --> 19:06.050
Uh, it's need to play the attack animation.

19:06.050 --> 19:09.570
So this player game object just gonna take the damage right away.

19:09.570 --> 19:15.610
So I hope you get the idea that how you can just, uh, do it, you can, uh, do with anything like

19:15.610 --> 19:16.810
that, and that's.

19:16.810 --> 19:17.770
It's pretty cool.
