WEBVTT

00:00.040 --> 00:01.880
We want to shoot out the arrow.

00:02.080 --> 00:06.080
So before we shoot out the arrow, we need to create our arrow.

00:06.240 --> 00:12.840
So let's head over to our project app assets and then sprites folder, and I will head over to my anime

00:12.880 --> 00:14.400
folder one folder.

00:14.400 --> 00:18.040
As you can see I have my arrow sprite right over here.

00:18.480 --> 00:19.640
So let's select that.

00:20.000 --> 00:23.480
So we're going to click on this arrow and we will select this one.

00:23.520 --> 00:26.720
Let's drag it over to this in view or into this hierarchy.

00:26.920 --> 00:31.440
So as you can see as soon as we drag it it seems a lot more small.

00:31.440 --> 00:34.320
So we need to make make it a little bit bigger.

00:34.320 --> 00:38.200
So we will select the sprite sprite from that folder.

00:38.200 --> 00:41.080
Then go over to Inspector and pixel per unit.

00:41.080 --> 00:46.400
We're gonna make it less so in order to make this sprite large in size.

00:46.400 --> 00:50.840
So we need to make this pixel per unit a less number and filter mode.

00:50.880 --> 00:53.760
We're going to choose point of filter to get rid of blurry.

00:53.800 --> 00:57.160
And let's click on this apply button in the bottom right.

00:57.160 --> 01:01.020
And now as soon as we have done it we can see our arrow?

01:01.500 --> 01:05.220
Uh, but it's, uh, facing to the right direction.

01:05.220 --> 01:09.620
So we want to flip this arrow horizontally in the left direction.

01:09.620 --> 01:11.460
So we will select our arrow.

01:11.500 --> 01:14.260
Let's go over to Sprite Renderer in Inspector.

01:14.260 --> 01:18.300
And we're going to check the flip in the X basically horizontally.

01:18.460 --> 01:22.580
And let's call it arrow instead of calling arrow underscore zero.

01:22.780 --> 01:24.460
So let's call it arrow.

01:24.660 --> 01:26.540
So we will add some component.

01:26.540 --> 01:30.260
First thing I'm going to add a rigid body 2D for gravity.

01:30.260 --> 01:32.420
And I'm going to set the gravity equal to zero.

01:32.420 --> 01:34.700
So it's not going to fall down at all.

01:34.860 --> 01:37.020
Or we can just set it to kinematic.

01:37.020 --> 01:39.060
So let's click on this add component.

01:39.060 --> 01:41.740
And let's find rigid body 2D by typing.

01:41.780 --> 01:43.260
And let's attach that.

01:43.460 --> 01:47.980
And I'm gonna set this body type to kinematic and collision detection.

01:47.980 --> 01:51.420
We're going to choose continuous and interpolate.

01:51.420 --> 01:54.740
We can choose interpolate to making a little bit more.

01:54.900 --> 01:59.140
And let's let's add another component for collision detection.

01:59.140 --> 02:01.600
So let's click on this add component.

02:01.600 --> 02:03.960
And we're going to add a box Collider 2D.

02:03.960 --> 02:05.400
And let's attach that.

02:05.640 --> 02:09.040
And let's click on this Edit Collider right over here.

02:09.040 --> 02:12.880
And let's edit the collider as the size of our arrow.

02:13.680 --> 02:16.840
Sorry let's click on this Edit Collider.

02:17.120 --> 02:20.000
And this seems pretty much fine.

02:20.000 --> 02:24.880
And once you are satisfied then you are good to go.

02:25.240 --> 02:29.840
And now what we want to do, we want to assign this arrow as a arrow tag.

02:29.840 --> 02:32.200
So we will choose our arrow in the hierarchy.

02:32.240 --> 02:34.440
Let's go over to Inspector and Tag.

02:34.480 --> 02:36.520
As you can see it says tag.

02:36.520 --> 02:37.520
So let's click there.

02:37.520 --> 02:39.000
Let's click on Add tag.

02:39.160 --> 02:44.040
Then click on this plus icon, name the tag whatever you want and then click on save.

02:44.080 --> 02:48.600
I already created a arrow tag as you can notice right over here.

02:48.600 --> 02:51.400
So I'm going to choose my arrow one more time in the hierarchy.

02:51.520 --> 02:54.800
Go over to Inspector and Tag which says untagged.

02:54.800 --> 02:56.880
We're gonna assign with our arrow.

02:56.920 --> 03:01.980
Now we assign it this arrow as arrow tag, As you can see in the inspector.

03:02.580 --> 03:04.100
So I hope you get the idea.

03:04.300 --> 03:06.900
Now let's turn this arrow into a prefab.

03:06.900 --> 03:11.340
So we will have the copy, and we will spawn it via when we need it.

03:11.340 --> 03:17.740
So let's select our arrow in the hierarchy, and let's drag it over to this prefabs folder in our project

03:17.780 --> 03:20.100
tab inside this assets folder.

03:20.140 --> 03:22.060
Now we turn it into a prefab.

03:22.060 --> 03:26.860
So let's select the arrow in the hierarchy and let's delete it from the scene view now.

03:26.860 --> 03:34.340
And we want to spawn it once this enemy GameObject just shooting out basically playing that arrow fire

03:34.380 --> 03:35.460
animation clip.

03:35.460 --> 03:38.340
So we will open up our enemy one script.

03:38.340 --> 03:40.020
So let's double click on it.

03:40.220 --> 03:44.860
And so first thing what we need we need a reference of that arrow prefab.

03:45.020 --> 03:49.380
So if I move over to my project tab assets and then prefabs folder.

03:49.420 --> 03:52.580
As you can see we have the arrow right over here.

03:52.580 --> 03:55.460
And this arrow itself a whole game object.

03:55.460 --> 03:56.900
So we need a reference.

03:56.900 --> 03:59.220
And after that we can just shoot out that.

03:59.220 --> 04:05.840
So let's go over to our anime one and let's go to top of our class and let's make it over here.

04:05.840 --> 04:08.240
So let's make a another serialized field.

04:08.880 --> 04:11.480
Uh, private, uh, private.

04:11.480 --> 04:12.120
Sorry.

04:12.160 --> 04:15.840
This will be private, and the component will look sorry.

04:15.880 --> 04:16.840
Not component.

04:17.040 --> 04:19.360
Are we looking for our game object?

04:19.360 --> 04:21.160
So we're going to type game object.

04:21.160 --> 04:23.040
And the game object is arrow.

04:23.040 --> 04:26.200
So we can simply call it something like arrow prefab.

04:26.320 --> 04:28.160
So let's call it arrow prefab.

04:28.400 --> 04:31.680
And let's close that off with semicolon.

04:31.680 --> 04:36.600
And make sure you press down Ctrl S to save your script and then move over to unity.

04:36.760 --> 04:41.840
So underneath our anime one script a field just gonna pop up says Arrow Prefab.

04:41.840 --> 04:47.480
So what we need to do there, we basically have to select our arrow prefab from this prefab folder,

04:47.480 --> 04:49.760
and we need to drag it over to that slot.

04:49.760 --> 04:51.360
So we will have the reference.

04:51.360 --> 04:54.320
And then we can just spawn it when we need it.

04:54.320 --> 04:57.080
So let's select our anime one in the hierarchy.

04:57.200 --> 05:03.620
As you can see underneath our enemy one we can see arrow prefab and it says non-game object.

05:03.620 --> 05:08.700
So let's choose our arrow prefab from that prefabs folder and let's drag it over here.

05:08.740 --> 05:14.500
Now we can see we have the arrow prefab as you can notice, and we are ready to spawn it.

05:14.500 --> 05:17.620
So let's open up our enemy one script one more time.

05:17.620 --> 05:22.220
And for that we will make a function to spawn our arrow.

05:22.220 --> 05:24.860
So let's make it somewhere around here.

05:25.060 --> 05:29.660
And we're going to make this function public since we're going to call this function through animation

05:29.700 --> 05:30.180
event.

05:30.180 --> 05:31.380
So let me explain.

05:31.380 --> 05:36.820
If I move over to unity, select this anime one and then move over to animation tab.

05:36.820 --> 05:43.020
And then click over here and then choose this arrow one sorry enemy one underscore arrow fire animation

05:43.020 --> 05:43.580
clip.

05:43.580 --> 05:48.420
So we want to call the function somewhere over here as you can see.

05:48.420 --> 05:51.580
So this is just going to be perfect time in order to call.

05:51.580 --> 05:55.140
So we will call the function here through animation.

05:55.140 --> 06:00.920
So that's why we need to mark that function as public as we have done inside this player game.

06:00.960 --> 06:01.880
Object Attack.

06:02.280 --> 06:08.280
Uh, I hope you get the idea that how we can do it, uh, we have done the same thing inside this player

06:08.320 --> 06:12.840
game object once we basically calling the attack function.

06:12.840 --> 06:19.560
So let's move over to our script and let's make this function public and, uh, public void.

06:19.560 --> 06:23.000
And we can call this function to something like spawn arrow.

06:23.160 --> 06:25.520
So let's call it spawn arrow.

06:25.720 --> 06:28.720
And let's make first bracket and some curly brackets.

06:28.880 --> 06:36.320
And this function over here as if to spawn our arrow, we do know that we need to use this instantiate

06:36.320 --> 06:36.960
function.

06:36.960 --> 06:42.120
And we need to make this brackets and this instantiate function as a first argument.

06:42.120 --> 06:45.000
It's going to take the game object that we want to spawn.

06:45.000 --> 06:46.960
So in our case arrow prefab.

06:47.160 --> 06:51.160
And the second thing it's going to take the position from where we want to shoot out.

06:51.160 --> 06:57.160
So we also need to create our shoot point or fire point where from we want to fire.

06:57.280 --> 06:58.540
And the third Another argument.

06:58.540 --> 07:00.260
It's gonna take the rotation.

07:00.580 --> 07:03.060
Uh, so we need to assign those variable.

07:03.060 --> 07:07.380
So let's make this one comment for now by double forward slash.

07:07.380 --> 07:09.380
And let's go to top of our class.

07:09.380 --> 07:11.540
And let's grab those reference first.

07:11.540 --> 07:15.300
So the first thing we need we have the arrow prefab.

07:15.460 --> 07:17.940
So the second thing we need our position.

07:17.940 --> 07:22.740
So let's make a serialized pill private a private.

07:22.740 --> 07:28.420
And for position we're going to type this transform which is responsible responsible for position.

07:28.420 --> 07:31.060
And we can call this one fire point.

07:31.060 --> 07:32.860
So let's call it fire point.

07:32.860 --> 07:34.980
And let's close that up with semicolon.

07:34.980 --> 07:40.300
And let's create another variable for our arrow speed with how much speed.

07:40.340 --> 07:42.300
We just want to shoot out the arrow.

07:42.300 --> 07:48.100
So let's create another serialized field private and we can call this will be float.

07:48.100 --> 07:54.500
And we can call this one arrow arrow speed something like that or arrow fire speed.

07:54.740 --> 07:58.720
And by default I'm going to set equal to ten unit Ten F.

07:58.880 --> 08:03.280
And let's press down control S on our keyboard in order to save our skate.

08:03.320 --> 08:05.320
And now let's move over to unity.

08:05.600 --> 08:08.400
So we will see underneath our enemy one.

08:08.400 --> 08:09.280
Skip those fields.

08:09.280 --> 08:10.240
Just gonna pop up.

08:10.360 --> 08:14.000
So first thing we need to assign our, uh, fire point.

08:14.000 --> 08:20.160
So we basically have to create our fire point from where we want to shoot out the, uh, shoot out,

08:20.160 --> 08:22.440
or want to fire our arrow.

08:22.520 --> 08:24.320
So we need to assign that.

08:24.320 --> 08:30.440
As you can see, as soon as our skip compiles, we can see fire point and it says none transform.

08:30.560 --> 08:32.520
So let's create our fire point.

08:32.680 --> 08:35.720
So let's select our enemy one GameObject in the hierarchy.

08:35.720 --> 08:37.480
Let's create a right click on it.

08:37.480 --> 08:39.960
And let's create an empty game object.

08:39.960 --> 08:46.960
And we can call this GameObject to something like fire uh fire point, uh fire point.

08:47.240 --> 08:49.560
And let's choose an gizmos for it.

08:49.560 --> 08:53.320
So let's go over to Inspector, click here and I'm gonna choose this one.

08:53.520 --> 08:56.360
And let's move it somewhere around here.

08:56.800 --> 09:00.540
And you can check that by selecting your anime one.

09:00.580 --> 09:05.020
Then moving over to animation tab, then choose the Arrow Animation clip.

09:05.180 --> 09:09.140
So I guess Arrow Fire should be right over here.

09:09.260 --> 09:11.220
So this is gonna be perfect point.

09:11.340 --> 09:13.540
So make sure you just adjust that.

09:13.540 --> 09:15.740
And now this seems pretty much fine.

09:15.980 --> 09:22.340
And once you are satisfied, make sure if you turn it your anime one into prefab, then go over to Inspector

09:22.340 --> 09:24.380
Overrides and then apply all.

09:24.540 --> 09:29.340
And we're going to take our fire point and let's drag it over to this fire point slot.

09:29.380 --> 09:34.660
Now we can see we have the fire point as well as the arrow, and we are ready to spawn it.

09:34.660 --> 09:39.300
So let's open up our anime one strip and let's move over to that function.

09:39.300 --> 09:42.180
And let's remove this two forward slashes.

09:42.180 --> 09:45.180
So this instantiate function as a first argument.

09:45.180 --> 09:48.060
It's going to take the GameObject that we want to spawn.

09:48.060 --> 09:51.700
So we will pass our arrow prefab and arrow prefab.

09:51.740 --> 09:56.260
We do know that we just pass our arrow as you seen earlier.

09:56.260 --> 09:58.520
And the second thing it's going to take the point.

09:58.520 --> 10:02.040
So we will pass our fire point dot position.

10:02.040 --> 10:07.600
And we do know that as a fire point we just drag it that fire point as you seen.

10:07.880 --> 10:10.440
And the third argument it's going to take the rotation.

10:10.440 --> 10:13.360
So we're going to put two quaternion dot identity.

10:13.400 --> 10:15.400
It basically means no rotation.

10:15.400 --> 10:17.680
And let's close that up with semicolon.

10:17.680 --> 10:20.520
And we're going to press down Ctrl s to save our script.

10:20.520 --> 10:22.320
And now let's move over to unity.

10:22.640 --> 10:25.400
So we just created that spawn arrow function.

10:25.400 --> 10:29.320
So we also need to call in order to spawn our arrow.

10:29.320 --> 10:37.760
So when we need to call it once our enemy this enemy one basically playing that arrow fire animation

10:37.760 --> 10:38.240
clip.

10:38.240 --> 10:41.040
So we will select our enemy one in the hierarchy.

10:41.080 --> 10:42.880
Then move over to animation tab.

10:42.880 --> 10:46.920
Let's click here and we're going to choose our Arrow Fire animation.

10:46.920 --> 10:49.600
Let's move it over to something over here.

10:49.600 --> 10:51.400
So this is going to be perfect time.

10:51.400 --> 10:55.800
So from here we want to call this function which is our spawn arrow.

10:56.080 --> 11:02.100
And in order to call that in this animation tab in the left side we can see Add event basically right

11:02.100 --> 11:02.580
over here.

11:02.580 --> 11:05.260
So just click that and then select that event.

11:05.300 --> 11:06.700
Then go over to Inspector.

11:06.740 --> 11:08.140
As you can see function.

11:08.140 --> 11:09.900
And it says no function.

11:09.900 --> 11:14.540
So we will click there and we will go to anime script or anime class.

11:14.580 --> 11:16.420
Then methods basically function.

11:16.420 --> 11:19.780
And there as you can see we created spawn arrow function.

11:19.780 --> 11:21.140
So we're going to choose that.

11:21.140 --> 11:28.780
Now uh, whenever this anime is just going to play this animation clip right over here, that uh, spawn

11:28.820 --> 11:31.060
arrow function, just going to call out.

11:31.060 --> 11:36.220
And we do know that what that function is really doing, it just spawning our arrow.

11:36.220 --> 11:37.180
So let's have a look.

11:37.220 --> 11:41.420
As you can notice right over here I'm going to clear my console tab.

11:41.860 --> 11:46.780
And let's click on this play button in the top in order to play our game.

11:46.780 --> 11:48.900
And let's get in attack range.

11:48.900 --> 11:54.460
So when we whenever we're gonna move over to our attack range you will see that.

11:56.100 --> 11:57.200
So just wait.

11:58.760 --> 12:05.920
So if we get in attack range, as you can see, as soon as we get we can see arrow prefab just spawning

12:05.920 --> 12:06.720
from that.

12:07.040 --> 12:10.000
Uh, and you can notice right over here.

12:10.000 --> 12:14.160
But the problem is that it's staying at one position.

12:14.160 --> 12:17.960
Also it's pushing our player to the right direction.

12:18.040 --> 12:21.760
So what we need to do, we basically have to tweak some values.

12:21.960 --> 12:24.080
So firstly it's not moving.

12:24.080 --> 12:25.640
So let's get out of play mode.

12:25.880 --> 12:33.280
Uh before we do it let's add let's deal with uh, that uh, our arrow just pushing our player to the

12:33.280 --> 12:34.120
right direction.

12:34.160 --> 12:39.800
So basically what we have to do, we need to move over to our project tab, then assets and then prefabs

12:39.800 --> 12:40.360
folder.

12:40.360 --> 12:42.440
And we will select our arrow prefab.

12:42.440 --> 12:45.320
Then go over to Inspector, then Box Collider 2D.

12:45.320 --> 12:47.840
And make sure you just check this trigger.

12:47.840 --> 12:50.840
So it's just gonna, uh check for trigger.

12:50.840 --> 12:58.740
So uh, trigger and it's not gonna push, uh, our player, uh, player basically for trigger and now

12:58.780 --> 12:59.980
and that's fine.

13:00.180 --> 13:02.740
And now it's not gonna push our player.

13:02.740 --> 13:05.340
So let's click on this play button in the top.

13:05.540 --> 13:08.020
Basically we just checking for trigger.

13:08.020 --> 13:12.420
And, uh, when we gonna trigger, uh, with anything.

13:12.420 --> 13:14.140
Not, uh, for collision.

13:14.140 --> 13:17.540
So when we're gonna trigger, that just gonna happen.

13:17.940 --> 13:20.620
It's not gonna push our player, as you can see.

13:20.660 --> 13:22.620
And this seems pretty much fine.

13:22.940 --> 13:28.380
When we get outside of this attack range, we can see enemy stops shooting out.

13:28.580 --> 13:29.900
Uh, arrow, arrow.

13:29.900 --> 13:37.780
Once we are out of, uh, once we are out of from our attack range of this enemy one game object.

13:37.780 --> 13:41.660
So these arrows are just staying at one position.

13:41.660 --> 13:45.660
So we need to just we need to move this arrow.

13:45.660 --> 13:47.380
So let's get out of play mode.

13:47.380 --> 13:52.900
And in order to move that arrow, we basically have to grab the reference of this rigid body.

13:52.900 --> 13:58.770
So if we if I select my arrow prefab from that prefab folder and go over to Inspector.

13:58.810 --> 14:02.130
As you can see, we added a rigid body to the component.

14:02.130 --> 14:08.930
And this component is responsible for velocity, adding force and all of kind of things.

14:09.010 --> 14:15.730
So what we need we need a reference of this component which is rigid body 2D of this arrow prefab GameObject.

14:15.770 --> 14:18.810
Then we can just add a add up the velocity.

14:18.930 --> 14:22.170
So let's go over to Inspector Sorry script.

14:22.610 --> 14:26.810
So we spawning this arrow prefab at this position with no rotation.

14:26.810 --> 14:31.650
So after spawning that arrow we're going to put that arrow into another game object.

14:31.650 --> 14:36.490
Or you can simply say into another container and that will be GameObject.

14:36.530 --> 14:36.890
Why?

14:36.930 --> 14:41.010
Because this arrow prefab itself a game object and we have to name it.

14:41.010 --> 14:44.810
So we can call this one arrow prefab.

14:44.810 --> 14:47.290
So let's call it arrow prefab.

14:47.530 --> 14:50.010
And let's set equal to this.

14:50.010 --> 14:51.130
Basically what we're doing.

14:51.130 --> 14:58.230
We just are taking this arrow prefab where wherever we spawning and we just storing that arrow that

14:58.230 --> 15:01.430
we spawn it into this arrow prefab.

15:01.590 --> 15:05.230
And now what we're going to do, we're going to access the rigid body.

15:05.350 --> 15:12.070
So we will use this stem arrow prefab dot game object dot get component.

15:12.070 --> 15:15.150
And the component we're looking for is a rigid body 2D.

15:15.150 --> 15:18.750
So we're going to type rigid body 2D and then make this brackets.

15:19.030 --> 15:22.630
And we can set equal to uh sorry.

15:22.670 --> 15:24.350
We can set the velocity.

15:24.350 --> 15:28.830
So we will type this linear velocity equal to that we want.

15:28.870 --> 15:30.950
So let me explain one more time.

15:30.990 --> 15:37.710
Firstly we spawning this arrow prefab in from this spawn position which is fire point or position with

15:37.710 --> 15:38.510
no rotation.

15:38.710 --> 15:44.750
And after spawning we just taking that arrow prefab and we storing that arrow prefab into this stem

15:44.790 --> 15:45.750
arrow prefab.

15:45.870 --> 15:51.790
And after that what we're doing we're just going over to temp arrow prefab and accessing the whole game

15:51.830 --> 15:52.190
object.

15:52.190 --> 15:56.610
So in our case basically we're just going over to this arrow game object.

15:56.610 --> 16:00.890
And then we're using this dot get component in order to get the component.

16:00.890 --> 16:05.890
And the component we're looking for is a rigid body 2D as you can see right over here.

16:05.930 --> 16:12.290
Basically we're just going over to this arrow prefab and then accessing this rigid body 2D and then

16:12.330 --> 16:14.570
accessing the velocity of it.

16:14.570 --> 16:17.770
Linear velocity as you can see right over here.

16:17.930 --> 16:18.450
Sorry.

16:20.490 --> 16:21.450
Just a little bit.

16:21.490 --> 16:22.810
I really apologize.

16:23.410 --> 16:24.290
Let's go back.

16:24.690 --> 16:29.450
So we just accessing the velocity linear velocity of that arrow.

16:29.650 --> 16:32.650
And now what we have to do we need to set the velocity.

16:32.810 --> 16:40.730
So firstly what we will do we will set the velocity with our uh basically uh we created arrow Spirit

16:40.730 --> 16:41.770
right over here.

16:41.770 --> 16:43.970
So we're going to pass our arrow speed.

16:44.010 --> 16:45.930
So let's pass arrow speed.

16:46.250 --> 16:46.970
Arrow speed.

16:46.970 --> 16:49.130
And let's close that off with semicolon.

16:49.450 --> 16:52.450
Uh so as you can see we're getting an error.

16:52.450 --> 16:55.110
Basically we need to convert this into a factor two.

16:55.310 --> 16:59.510
Basically what we will do right over here we're going to put transform.

16:59.830 --> 17:00.310
Sorry.

17:01.550 --> 17:04.710
Uh transform transform dot.

17:05.030 --> 17:06.430
Sorry not transform dot.

17:06.470 --> 17:07.030
Right.

17:07.070 --> 17:10.950
Basically we're going to use fire point dot right.

17:11.110 --> 17:12.550
Fire point dot right.

17:12.550 --> 17:18.710
So what basically this mean fire point dot right means that which direction our fire point is facing.

17:18.710 --> 17:24.510
So if I choose my fire point underneath my enemy point game object in the hierarchy, as you can see,

17:24.710 --> 17:27.550
our fire point is facing right direction.

17:27.550 --> 17:32.790
So fire point dot right basically means which direction our fire point is facing.

17:32.790 --> 17:36.750
So we want to move our arrow prefab to the left direction.

17:36.750 --> 17:41.830
So that's why right in front of this fire point dot right we're going to put minus.

17:41.830 --> 17:43.950
Now it's going to be left direction.

17:43.950 --> 17:48.950
And we we're just going to multiply that direction with our arrow speed.

17:48.950 --> 17:52.030
So as so our arrow is just going to move.

17:52.030 --> 17:53.030
So what we will do.

17:53.070 --> 17:57.850
We just going to want to multiply this 5.0 right, with our arrow speed.

17:57.970 --> 17:58.690
Arrow speed.

17:58.730 --> 18:00.170
Let's multiply that.

18:00.170 --> 18:04.850
And now that arrow is just gonna move with this arrow speed.

18:04.850 --> 18:11.090
So firstly what we're doing we just accessing the rigid body 2D component of that arrow prefab and then

18:11.090 --> 18:12.570
accessing the velocity.

18:12.570 --> 18:17.570
And we setting the velocity equal to which direction our fire point is facing.

18:17.570 --> 18:22.650
And we just put minus basically now it's gonna be a left direction.

18:22.650 --> 18:25.770
And we just multiply that direction with our arrow.

18:25.770 --> 18:32.490
Speed basically means that that arrow just gonna move with uh, with this much of arrow speed, as we

18:33.250 --> 18:35.170
specified right over here.

18:35.170 --> 18:41.650
So since we just made it serialized field so we can access this parameter underneath our enemy one script.

18:41.650 --> 18:44.810
So there we can just adjust if we want.

18:45.050 --> 18:49.290
So now what we're gonna do, we're gonna press control S to save our script.

18:49.290 --> 18:52.250
And now let's move over to unity and you will see.

18:55.830 --> 18:59.630
So just wait a little moment and you will see that.

19:04.030 --> 19:05.950
So let's have a look.

19:06.630 --> 19:09.230
So I'm going to click on this play button in the top.

19:09.230 --> 19:16.510
So as soon as this anime one game object just going to play arrow fire animation clip then arrow just

19:16.510 --> 19:17.230
going to spawn.

19:17.230 --> 19:19.950
And that arrow just going to move in the direction.

19:20.110 --> 19:22.830
Uh, in the direction uh, fire point is facing.

19:22.830 --> 19:28.110
Basically negative direction in the fire point is facing means to the left direction.

19:28.110 --> 19:29.870
So let's get in attack range.

19:29.870 --> 19:34.030
And we can see by now arrow is just going to the left direction.

19:34.030 --> 19:40.350
As you can see fire point dot right basically means right direction, the direction our fire point is

19:40.350 --> 19:40.950
facing.

19:40.950 --> 19:47.470
And we just put minus uh, to uh, to basically move uh, over to negative direction.

19:47.470 --> 19:50.070
And we can see indeed it's working fine.

19:50.230 --> 19:55.010
But the problem is that as you can see, uh, our, uh, arrow.

19:55.210 --> 20:00.850
Once we are to the right direction, we can see that our arrow is, uh.

20:01.610 --> 20:02.530
You can simply.

20:02.570 --> 20:03.770
I'm going to pause my game.

20:04.010 --> 20:08.050
Arrow is not facing to the, uh, to the right direction.

20:08.090 --> 20:12.330
Once we shooting out the shooting out this way, to the right direction.

20:12.330 --> 20:13.930
So we need to flip this.

20:14.010 --> 20:17.970
Uh, basically, we need to work with rotation of this arrow prefab.

20:17.970 --> 20:24.410
So let's get out of play mode and what we have to basically do their, uh, so instead of typing quaternion

20:24.410 --> 20:27.130
dot identity basically means no rotation.

20:27.170 --> 20:34.210
We're going to pass this fire point dot rotation and fire point dot rotation basically means the rotation

20:34.210 --> 20:36.050
fire point is facing.

20:36.050 --> 20:38.010
Now it should be work fine.

20:38.010 --> 20:40.890
So we're going to press down Ctrl S to save our script.

20:40.930 --> 20:42.770
And let's move over to unity.

20:42.770 --> 20:50.210
So now by by now that arrow just gonna rotate in the direction fire point is rotating.

20:50.490 --> 20:52.490
So it will be okay by now.

20:52.490 --> 20:56.270
But, before we have it, let's take a look on it.

20:57.590 --> 21:00.990
So what we will do, we're going to play our game.

21:01.270 --> 21:04.590
Firstly I'm going to select my enemy one game object in the hierarchy.

21:04.590 --> 21:07.830
And let's press down F in order to focus on it.

21:08.190 --> 21:12.190
So let's click on this play button in the top in order to play our game.

21:12.190 --> 21:14.030
And let's test that out.

21:15.550 --> 21:22.230
So now the rotation just gonna just gonna be find of that arrow because we just type fire point dot

21:22.270 --> 21:29.630
rotation basically means that arrow just gonna rotate rotate with our fire point dot rotation.

21:29.630 --> 21:30.670
So let's get in.

21:30.910 --> 21:32.350
And if we just move.

21:32.350 --> 21:38.310
And now as you can notice, if I pause my game, we can see the rotation of this arrow.

21:38.350 --> 21:40.150
It's now to the right direction.

21:40.150 --> 21:47.310
Once our player once our enemy one shooting out the arrow to the right direction.

21:47.350 --> 21:51.350
Now our arrow just facing to the right direction.

21:51.350 --> 21:52.810
So Direction.

21:52.810 --> 21:54.690
We just work with rotation.

21:54.690 --> 22:00.130
So instead of passing right over here, quaternion dot identity basically means no rotation.

22:00.130 --> 22:06.730
Pass fire point dot rotation means the rotation will be with our fire point dot rotation.

22:06.730 --> 22:11.530
So I hope you get the idea and what we need to do after some period of time.

22:11.530 --> 22:13.450
We need to destroy these arrows.

22:13.730 --> 22:15.930
We need to destroy these arrows.

22:15.930 --> 22:18.090
So let's get out of play mode for it.

22:18.090 --> 22:19.770
We're gonna create a script.

22:19.770 --> 22:24.330
So what we're gonna do and we're gonna attach that script to this, our arrow.

22:24.530 --> 22:26.410
So let's create a script for it.

22:26.410 --> 22:30.770
So we will head over to our project tab assets and then script folder.

22:30.810 --> 22:34.530
Let's right click there then create Monobehaviour script.

22:34.530 --> 22:38.770
Or you can move over to scripting and then click on this Monobehaviour script.

22:38.770 --> 22:41.250
And you can name that script whatever you like.

22:41.250 --> 22:42.970
Just name it something like arrow.

22:43.210 --> 22:46.970
As you can see, I already created a arrow script.

22:46.970 --> 22:49.770
So what I'm going to do, I'm going to select my arrow prefab.

22:49.810 --> 22:51.410
Let's double click on it.

22:51.450 --> 22:56.910
And in order to open that up in prefab mode, and we're gonna attach our arrow script.

22:56.910 --> 23:02.190
So I will head over to my script folder and let's select this arrow script and drag it over to this

23:02.230 --> 23:04.550
add Component section and Inspector.

23:04.550 --> 23:07.110
Or we can simply click on this add component.

23:07.110 --> 23:12.430
And we can find the script by typing the name of the script which is arrow, and we can hit enter in

23:12.430 --> 23:13.870
order to attach that.

23:13.910 --> 23:17.790
I'm not gonna do it twice since I already attached my arrow script.

23:17.790 --> 23:22.670
So I'm gonna go back and let's open up the arrow script by double clicking on it.

23:22.670 --> 23:27.830
Make sure you attach this as arrow script, uh, to that arrow game object.

23:27.830 --> 23:30.430
So we will move over to this start function.

23:30.430 --> 23:34.430
So we do know that start function get call in the start of the game.

23:34.430 --> 23:36.990
So in the start of the game we will destroy.

23:36.990 --> 23:39.430
But we don't want to destroy immediately.

23:39.470 --> 23:42.230
We want to destroy after some period of time.

23:42.230 --> 23:46.230
So as a second argument we can just specify the time.

23:46.470 --> 23:50.350
So to destroy we're gonna use destroy this destroy function.

23:50.350 --> 23:55.690
And this destroy function as a first argument, it's going to take the game object we want to destroy.

23:55.810 --> 23:58.650
So we want to destroy game object itself.

23:58.650 --> 24:01.210
So we will pass this dot game object.

24:01.210 --> 24:06.450
And this dot game object basically means it's referencing our game object itself comma.

24:06.490 --> 24:08.690
Second thing it's going to take the time.

24:08.690 --> 24:11.810
So after five seconds I want to destroy or seven.

24:11.810 --> 24:15.810
So I'm gonna put seven and then close that up with semicolon.

24:15.970 --> 24:21.850
And if you want to adjust then you can just go over to top of your class and you can make a variable

24:21.850 --> 24:22.450
for it.

24:22.450 --> 24:24.370
So let's make a serialize field.

24:24.730 --> 24:29.290
So alias field private and private this will be float.

24:29.290 --> 24:32.890
And we can call this something like destroy time.

24:32.890 --> 24:37.490
So let's call it Destroy and destroy time.

24:37.490 --> 24:40.090
And by default I'm going to set it to something like five.

24:40.530 --> 24:44.050
And let's replace this seven F with our destroy time.

24:44.370 --> 24:47.250
So let's replace this with our destroy time.

24:47.450 --> 24:53.230
And we do know that we just marked as serialized field so we can adjust the time in Inspector and we

24:53.230 --> 24:54.870
will remove this update function.

24:54.870 --> 24:58.750
We don't need it and we're going to use some certain function later.

24:58.990 --> 25:02.470
So let's press down Ctrl S in order to save our script.

25:02.470 --> 25:07.630
And let's have a look and make sure you attach that script to your arrow game object.

25:07.950 --> 25:15.910
Uh, so, uh, so our arrow is just gonna destroy itself after with our, uh, after, uh, after,

25:15.910 --> 25:18.950
you can say with destroy time.

25:19.510 --> 25:23.110
Destroy time, as we specified in our script.

25:23.110 --> 25:25.790
So now let's have a look.

25:25.790 --> 25:27.670
So I'm going to click on this play button.

25:27.670 --> 25:35.270
So you will see as soon as our uh, as soon as, uh, our destroy time just going to be over basically

25:35.470 --> 25:39.070
arrow just going to destroy itself after that amount.

25:39.110 --> 25:40.150
Destroy time.

25:40.630 --> 25:41.670
So let's have a look.

25:41.670 --> 25:45.950
So if I if we get in attack range, we can see it's shooting out the ray.

25:45.950 --> 25:52.930
And you will see this arrow just going to destroy itself after after that destroy time amount.

25:52.970 --> 25:56.450
As you can see, indeed it destroying right over here.

25:56.450 --> 25:59.850
So after something like five seconds it just destroying itself.

25:59.930 --> 26:05.690
So if I get out of play mode and then move over to my prefabs folder and then select this arrow, we

26:05.690 --> 26:08.410
can see our in our arrow script.

26:08.410 --> 26:11.570
In Inspector Destroy Time, we have chosen five.

26:11.610 --> 26:12.770
You can make it less.

26:12.770 --> 26:13.930
You can make it bigger.

26:13.930 --> 26:15.570
It's basically up to you.

26:15.570 --> 26:21.890
So I hope you get the idea that how you can just do it and make sure you attach your arrow script to

26:21.930 --> 26:23.970
your arrow prefab game object.

26:23.970 --> 26:27.530
So it's gonna do that thing, or else you're gonna get some error.

26:27.530 --> 26:35.850
So you need to make sure that and whatever changes we have done now in in this anime one game object.

26:35.850 --> 26:39.810
So let's move over to Inspector Overrides and then apply all.

26:39.810 --> 26:46.490
So the changes we made over here, it's going to be saved into this enemy one GameObject prefab as well.

26:46.690 --> 26:51.650
And I'm gonna press Ctrl S on my keyboard in order to save my project.
