WEBVTT

00:00.080 --> 00:00.500
Hello guys.

00:00.500 --> 00:01.370
Welcome to the video.

00:01.370 --> 00:06.320
In this one I want to make another flying enemy and this video will be a good opportunity to show you

00:06.320 --> 00:07.670
another trick to learn.

00:07.670 --> 00:13.850
Let's go to Prefabs enemies and let's make prefab out of the enemy ghost like that.

00:13.850 --> 00:19.670
Then I'm going to do prefab unpack completely and we need to change name to Enemy Be.

00:20.450 --> 00:23.540
Let's go to asset animations.

00:23.540 --> 00:24.800
Enemies.

00:25.660 --> 00:27.730
Uh, we need to make a folder.

00:28.420 --> 00:29.050
Be.

00:30.450 --> 00:33.090
Then inside we need to make animator.

00:33.600 --> 00:36.570
This is going to be enemy b a c.

00:38.320 --> 00:41.830
And then we need to go to animations.

00:44.730 --> 00:48.780
I'm going to select B and drag the animator controller.

00:48.780 --> 00:51.090
And then let's create a couple of clips.

00:51.360 --> 00:54.150
This one going to be enemy B idle.

00:54.420 --> 00:55.080
Nice.

00:55.080 --> 01:02.580
Now we need to go to Graphics enemies B let's take these and make pixel per unit 16.

01:03.300 --> 01:06.690
And then I want to take the idle sprites and drag them here.

01:06.690 --> 01:09.000
Sample rate 20.

01:10.370 --> 01:15.980
Also, let's take the sprite renderer over here and let's turn it into a b.

01:16.460 --> 01:18.950
Okay, this is good I like it.

01:19.070 --> 01:26.120
And now we need one more for the hit create new clip enemy B hit.

01:26.980 --> 01:28.630
Can I take the heat sprites?

01:28.630 --> 01:29.650
Drag them here.

01:29.650 --> 01:31.300
Sample rate 20.

01:32.200 --> 01:34.840
And then we need just one more for the attack.

01:35.820 --> 01:38.100
Enemy the attack.

01:38.760 --> 01:41.940
Let's save this and let's take a tax rates.

01:42.450 --> 01:43.440
Drag them here.

01:43.440 --> 01:45.000
Sample rate 20.

01:46.030 --> 01:47.050
Okay.

01:47.050 --> 01:49.390
This is good, I like it.

01:49.450 --> 01:51.670
Now let's go to animator.

01:53.910 --> 01:54.450
Over here.

01:54.450 --> 01:58.500
We're going to be in the idle, then we're going to trigger attack.

01:58.830 --> 02:02.700
So let's do a trigger attack.

02:03.310 --> 02:07.930
And then we need transfer to be attack from an idol.

02:10.170 --> 02:10.950
Has exit time.

02:10.950 --> 02:11.370
Uncheck.

02:11.400 --> 02:13.050
Transition duration zero.

02:13.080 --> 02:14.670
Then transfer back.

02:15.350 --> 02:23.210
With the exit time of one, transition duration zero, and we can enter enemy be hit from any state

02:23.210 --> 02:25.610
with a trigger hit.

02:32.770 --> 02:36.070
Let's do condition hit exit time.

02:36.070 --> 02:39.700
I mean transition duration zero can transit or self uncheck.

02:39.820 --> 02:42.790
That's all what we need for this setup of animator.

02:42.790 --> 02:46.780
Now my windows are a bit off so I'm going to do windows 2D.

02:46.960 --> 02:48.910
Sorry general where is it.

02:48.910 --> 02:53.350
Layouts two by three okay this is a bit better.

02:56.290 --> 02:57.100
Yes.

02:58.910 --> 03:01.310
Let me open animation.

03:03.800 --> 03:06.440
And window animator.

03:06.980 --> 03:08.780
All right, this should be okay.

03:08.780 --> 03:10.280
Also, we need a console.

03:11.020 --> 03:12.340
Add a tab.

03:12.370 --> 03:13.840
It's not here.

03:14.050 --> 03:14.920
Window.

03:14.920 --> 03:16.960
General console.

03:19.470 --> 03:20.340
Like that.

03:20.340 --> 03:21.090
Nice.

03:21.090 --> 03:22.230
Now we need a script.

03:22.230 --> 03:24.270
So I'm going to go to scripts folder.

03:24.690 --> 03:28.500
We're going to make a script in the enemies folder.

03:30.420 --> 03:33.150
It's going to be enemy B.

03:33.750 --> 03:36.750
Okay, uh, let's go on enemy B.

03:37.600 --> 03:39.820
Let's remove enemy ghost script.

03:42.800 --> 03:44.960
And let's add enemy B.

03:45.530 --> 03:46.310
Okay.

03:46.310 --> 03:48.110
Let's check colliders.

03:48.830 --> 03:50.540
I think it's pretty much okay.

03:50.540 --> 03:52.790
We don't need to change anything I like it.

03:52.790 --> 03:54.500
Maybe damage trigger.

03:54.920 --> 03:55.730
I should be good.

03:55.730 --> 03:56.630
It's enough.

03:56.690 --> 03:58.580
Now let's go to the script.

04:06.900 --> 04:09.330
And here is the script.

04:09.330 --> 04:11.670
And we want to inherit from the enemy.

04:13.760 --> 04:14.750
Enemy.

04:14.780 --> 04:20.900
Then over here we need to take a functionality from a plant, I guess, because it's going to be very

04:20.900 --> 04:24.230
similar to the plant, just slightly upgraded.

04:24.500 --> 04:26.810
So let me do close all by this.

04:26.990 --> 04:30.920
Then I'm going to go to enemy plant and we can just take.

04:31.860 --> 04:35.100
Uh, like entire script from here.

04:35.100 --> 04:36.210
Let's copy this.

04:36.210 --> 04:38.310
Go to NB and paste this in.

04:38.310 --> 04:41.430
And now we need to slightly change it.

04:43.360 --> 04:45.880
So first of all, we need a bullet for the B.

04:46.180 --> 04:48.850
Let's do here B details.

04:48.850 --> 04:51.040
And let's go and quickly create the.

04:52.010 --> 04:56.510
Be bullet script because it's going to behave in a special way.

04:58.780 --> 05:02.980
So we're going to go here and we're going to do C sharp script.

05:04.350 --> 05:06.420
Enemy bullet.

05:06.510 --> 05:07.290
B?

05:07.560 --> 05:08.070
Yeah.

05:08.070 --> 05:08.880
Like that.

05:09.420 --> 05:14.430
Now, inside of this script, we can use enemy bullet B.

05:15.160 --> 05:19.600
And let's go and adjust this script over here.

05:19.600 --> 05:22.960
So instead of enemy bullet we want to use enemy bullet be.

05:24.230 --> 05:29.060
By the way, I just realized we have enemy bullet script.

05:29.660 --> 05:32.600
So we can have a similar name.

05:32.990 --> 05:40.160
Let's press Ctrl RR and let's do enemy underscore bullet underscore B like that.

05:40.700 --> 05:41.480
Very nice.

05:41.480 --> 05:46.760
Now this bullet is not going to have velocity just like we had unplanned, because this bullet is going

05:46.760 --> 05:53.210
to target the player and it's going to follow the player like a auto targeting missile or something

05:53.210 --> 05:53.630
like that.

05:53.630 --> 05:59.270
You'll see it as of now, let's just remove these two lines of code and let's leave it as it is.

05:59.270 --> 05:59.870
Okay?

06:01.730 --> 06:02.630
Now.

06:02.630 --> 06:04.130
Let's go.

06:05.450 --> 06:06.560
Up to the header.

06:06.560 --> 06:08.360
We want to have bullet prefab.

06:08.360 --> 06:09.410
We need gunpoint.

06:09.410 --> 06:10.460
We need bullet speed.

06:10.460 --> 06:12.110
We need attack cooldown.

06:12.110 --> 06:14.540
Also, we need a serialized field.

06:14.540 --> 06:17.630
Private float bullet lifetime.

06:17.630 --> 06:22.670
Because this bullet is going to follow the player, we don't want it to follow the player.

06:22.670 --> 06:24.140
Like endlessly.

06:24.140 --> 06:26.060
We want to have some limitations on this.

06:26.060 --> 06:29.090
That's why we're going to have this variable bullet lifetime.

06:29.240 --> 06:33.200
We're going to just destroy the bullet after lifetime is over.

06:33.200 --> 06:34.190
Something like that.

06:34.190 --> 06:38.420
Now let's talk about targeting the player, how it's going to work.

06:38.420 --> 06:42.530
First of all, we want to have a private transform target.

06:43.850 --> 06:50.750
And we're going to fill up this target with, uh, any player that walked below the be this, what are

06:50.750 --> 06:51.380
we going to do?

06:51.380 --> 06:54.710
So let's go to update method and let's do this.

06:54.710 --> 06:58.970
If target is equals to null means we need to find the target.

06:58.970 --> 07:05.390
And we're going to look for a target with a raycast I'm going to do raycast hit 2D hit equals to physics

07:05.390 --> 07:08.330
2D raycast from.

07:08.330 --> 07:10.190
Uh transform.position.

07:11.200 --> 07:13.210
To vector two dot down direction.

07:13.210 --> 07:19.120
Because we want to aim down for the distance, we can really have a big distance because we want to

07:19.120 --> 07:19.990
detect player.

07:19.990 --> 07:25.840
In any case, if if that's the case then I'm going to do float max value.

07:25.840 --> 07:30.040
And what is player player like that.

07:30.250 --> 07:32.890
Then over here we're going to do something simple.

07:32.890 --> 07:40.030
If hit transform not equals to null then target equals to hit transform.

07:40.480 --> 07:41.830
And now we're going to assign target.

07:41.830 --> 07:43.090
If we find any.

07:43.540 --> 07:50.230
Then when we did perform the attack, when we did create a bullet we're going to do target equals to

07:50.230 --> 07:50.620
null.

07:50.620 --> 07:53.170
So we can look for a new target again.

07:53.170 --> 07:54.520
All right this is good.

07:54.520 --> 07:56.110
Now let's go back to update method.

07:56.110 --> 08:01.060
And over here boolean can attack will be true if we don't have cooldown.

08:01.060 --> 08:04.000
And if we have target.

08:04.630 --> 08:05.500
Just like that.

08:05.500 --> 08:11.830
And then over here we can remove this is player detected because we're doing similar check over here

08:11.950 --> 08:12.550
right.

08:12.550 --> 08:14.110
So we can remove it.

08:15.970 --> 08:18.220
And this should be good enough.

08:18.220 --> 08:19.540
This should work.

08:19.540 --> 08:24.400
And now, instead of creating a bullet, I'll just debug a message debug log.

08:25.750 --> 08:28.000
I created a bullet.

08:29.870 --> 08:32.240
We just want to be sure it is working.

08:32.720 --> 08:35.930
And we have a method same as it was on the plant.

08:38.840 --> 08:41.750
All right, let's go back to unity.

08:42.200 --> 08:46.190
We need to find the B and let me place it somewhere.

08:46.190 --> 08:47.690
Well, here is fine.

08:47.810 --> 08:49.100
Now, what is ground?

08:49.100 --> 08:49.760
Ground?

08:49.760 --> 08:50.810
What is player?

08:51.140 --> 08:52.130
What is player?

08:52.130 --> 08:53.090
Player?

08:53.090 --> 08:53.780
Ground.

08:53.780 --> 08:55.580
Check over here.

08:55.580 --> 08:56.150
Bullet.

08:56.150 --> 08:56.720
Prefab.

08:56.720 --> 08:57.890
We need to make it.

08:57.890 --> 08:59.360
We're not going to use it now.

09:01.090 --> 09:03.880
Let's make empty gunpoint.

09:05.000 --> 09:07.490
We're going to assign it over here.

09:07.490 --> 09:13.430
Let's focus on the gun point and move it over here to the bottom of the B.

09:14.100 --> 09:14.940
Like that.

09:16.440 --> 09:16.800
All right.

09:16.800 --> 09:18.090
This looks good to me.

09:19.850 --> 09:22.490
We also need to set up animation event.

09:23.200 --> 09:27.220
So we're going to go to animations find enemy, be attack.

09:27.220 --> 09:30.550
Let's find a frame where bullet supposed to fly out.

09:30.550 --> 09:38.110
So it is here we're going to add event function enemy be methods create bullet.

09:39.780 --> 09:40.530
All right.

09:40.530 --> 09:42.630
This is supposed to be ready to check.

09:43.140 --> 09:46.200
Let's go and try going to go to play mode.

09:49.310 --> 09:52.370
And it shoots and it creates a bullet.

09:52.370 --> 09:53.870
We can see a debug message.

09:55.040 --> 09:55.760
Nice.

09:55.760 --> 09:58.700
Now we need to set up bullet and that's what we're going to do.

09:58.790 --> 10:03.080
We're going to go to prefab, uh, enemies.

10:03.080 --> 10:06.530
There is this enemy bullet from plant.

10:06.980 --> 10:12.200
You can just drag it here and we want to do prefab unpack completely.

10:12.200 --> 10:17.600
Then we want to remove this script over here and we want to add enemy bullet be.

10:19.750 --> 10:23.560
Also I want to add damage trigger like that.

10:23.860 --> 10:25.090
It should be good enough.

10:25.090 --> 10:28.840
Now let's go to enemy bullet B and do a bit of a setup.

10:30.560 --> 10:33.200
This bullet is supposed to follow the player.

10:33.200 --> 10:36.350
So first of all, we need to have reference to the player.

10:36.350 --> 10:39.110
I'm going to do Private Transform target.

10:41.250 --> 10:46.560
Then this bullet is supposed to have a waypoint that it uses to follow the player.

10:46.560 --> 10:48.120
We can make a list.

10:48.420 --> 10:48.810
Private.

10:48.810 --> 10:52.110
List of Vector3.

10:53.150 --> 10:54.680
Waypoints.

10:55.040 --> 10:57.110
And let's make it as a new list.

10:57.110 --> 11:01.370
And we're going to fill up waypoints with the current position of the player.

11:01.670 --> 11:04.310
And we're going to do that with a bit of a cooldown.

11:04.310 --> 11:08.660
And because of that, we're going to add each new position of the player to this list.

11:08.660 --> 11:11.180
And then bullet will follow the trail.

11:11.180 --> 11:13.730
It will follow positions that player had.

11:14.390 --> 11:15.740
This is how it's going to be.

11:17.180 --> 11:20.930
Also going to need private int we index.

11:20.930 --> 11:28.550
And we're going to need let's do serialized field private float way point update.

11:31.140 --> 11:32.790
Pull down something like that.

11:32.790 --> 11:34.950
And we also want to have a speed.

11:34.950 --> 11:37.560
So let's do private float speed.

11:38.990 --> 11:44.360
Now we need a method that we're going to use to set up all of these variables from enemy B.

11:44.750 --> 11:48.950
So let's make public void set up bullet.

11:49.280 --> 11:51.710
We're going to pass transform new target.

11:51.710 --> 11:54.350
Then we're going to need float speed.

11:54.350 --> 11:56.060
Let's do new speed.

11:56.060 --> 11:57.470
And we need float.

11:58.550 --> 12:01.490
Um, life duration.

12:02.780 --> 12:04.010
Let's open this.

12:04.010 --> 12:07.400
Let's do, uh, speed equals to new speed.

12:08.000 --> 12:09.920
Target equals to new target.

12:09.920 --> 12:16.760
And then we want to do destroy game object in a live duration just like that.

12:18.700 --> 12:20.230
Well, this is good.

12:20.260 --> 12:25.990
Now let's make a coroutine that would add waypoints to the list.

12:26.940 --> 12:28.950
We're going to do a private.

12:30.520 --> 12:32.980
Void add waypoint.

12:34.030 --> 12:36.040
In which we're going to do something simple.

12:36.040 --> 12:38.950
If target is null, then we're going to return.

12:38.950 --> 12:43.780
Then we want to do waypoint add target dot position.

12:43.780 --> 12:49.570
And just in case I want to return from a method, if we try to add position that we already have.

12:49.570 --> 12:57.760
So I'm going to do for each vector three uh waypoint in waypoints.

12:58.300 --> 13:05.740
If waypoint is equals to a target dot, position means some of them is equals to the current position.

13:05.740 --> 13:08.320
And we then need to add same position.

13:08.320 --> 13:11.500
And if that's the case then we're going to return from a method.

13:12.630 --> 13:13.020
Okay.

13:13.020 --> 13:13.830
Very nice.

13:13.830 --> 13:17.040
Now we want to add waypoints with some sort of cooldown.

13:17.040 --> 13:19.530
And I think we can do that with a coroutine.

13:19.530 --> 13:23.130
I'm going to do uh, I enumerator.

13:24.270 --> 13:25.650
Let's do it as private.

13:26.190 --> 13:33.990
And the way point coroutine, in which we're going to do the same thing as we did on a blinking text.

13:35.690 --> 13:37.970
Over here is going to be very similar.

13:40.740 --> 13:44.670
So we're going to do while true and this will run endless loop for us.

13:44.670 --> 13:47.880
So while true and waypoint.

13:48.700 --> 13:50.140
And then wait.

13:51.490 --> 13:52.720
Yield return.

13:52.720 --> 13:54.070
New weight.

13:55.390 --> 13:59.050
Four seconds of waypoint update cooldown.

14:00.780 --> 14:04.800
And I think it's a good idea to start this coroutine when we set up the bullet.

14:04.800 --> 14:07.830
So I'm going to do start coroutine of a.

14:08.820 --> 14:09.870
And waypoint.

14:09.870 --> 14:10.680
Coroutine.

14:11.510 --> 14:12.260
Okay.

14:12.530 --> 14:15.140
And now this will add waypoints endlessly.

14:15.140 --> 14:17.180
And also we want to move the bullet.

14:17.180 --> 14:19.340
So I'm going to make an update.

14:19.790 --> 14:23.780
In the update we're going to do transform position equals to.

14:24.610 --> 14:32.950
Vector two move towards from a transform position to a waypoints with away index.

14:34.070 --> 14:36.950
With the speed multiplied by time, the delta time.

14:36.950 --> 14:43.970
And just to avoid any errors, we want to return if waypoints dot count is less or equals to zero.

14:45.800 --> 14:47.060
Okay, this is good.

14:47.060 --> 14:49.850
Then if we are close enough to the destination.

14:49.850 --> 14:57.080
If vector two, the distance between Transform.position and waypoints with a way index.

14:59.440 --> 15:05.590
Is a less than 0.1 F, then we are close enough and we can move to the next point.

15:05.590 --> 15:08.050
So I'm going to do way index plus plus.

15:08.050 --> 15:11.860
And also I want bullet to be facing the direction that is going to.

15:11.890 --> 15:19.180
So for that I'm going to do transform up which is a green axis equals to.

15:19.360 --> 15:22.600
And we're going to get direction from a current position to the waypoint.

15:22.600 --> 15:27.190
So equals to transform position minus waypoint waypoint index.

15:27.190 --> 15:32.740
And also would be nice to make it face the player once it flew out of the enemy.

15:32.740 --> 15:35.200
So I guess I'm going to copy this line of code.

15:35.530 --> 15:39.790
Go over here and over here we're going to do target instead of.

15:40.830 --> 15:41.940
Uh, the waypoint.

15:43.730 --> 15:44.180
Okay.

15:44.180 --> 15:45.260
This is supposed to be good.

15:45.260 --> 15:45.950
For now.

15:45.950 --> 15:48.380
Let's save everything.

15:48.380 --> 15:50.240
Let's go to enemy B.

15:53.990 --> 15:54.980
Over here.

15:54.980 --> 15:59.270
Since we have live duration on a bullet itself, we do need this line of code.

15:59.270 --> 16:02.180
But we need this line of code to make a bullet.

16:02.690 --> 16:05.840
And we're going to do new bullet setup.

16:05.840 --> 16:06.470
Bullet.

16:06.470 --> 16:08.660
We're going to pass target.

16:09.390 --> 16:14.940
We're going to pass, uh, bullet speed and bullet lifetime.

16:16.500 --> 16:17.490
Like that.

16:17.670 --> 16:18.540
Very nice.

16:18.540 --> 16:21.030
That's basically everything that we need for now.

16:21.360 --> 16:23.310
Let's go ahead and try this.

16:27.460 --> 16:27.760
Mm.

16:28.630 --> 16:32.380
Let's do waypoint cool down maybe 0.1.

16:32.860 --> 16:34.210
I'm going to see how it works.

16:34.210 --> 16:36.700
If I like it I'll just hide the variable.

16:36.700 --> 16:37.390
Okay.

16:37.570 --> 16:40.720
Let's go and make a prefab out of this one.

16:40.720 --> 16:42.940
We need to go to prefabs enemies.

16:42.940 --> 16:46.750
We can just rename it to Enemy Bullet Be.

16:50.640 --> 16:55.470
Also before I forgot, let's go to rigidbody and let's make it as kinematic.

16:56.540 --> 16:57.200
Okay.

16:57.880 --> 17:00.010
Now let's drag it over here.

17:00.010 --> 17:06.250
Then we're going to go to enemy B, take it from here and make it as a prefab over here.

17:06.910 --> 17:08.980
Very nice now.

17:11.110 --> 17:11.470
Let's see.

17:11.470 --> 17:12.730
This is the bullet here.

17:12.730 --> 17:15.580
We need to update the sprite something I forgot.

17:15.580 --> 17:21.220
Let's go to Graphics enemies B and there is this bullet.

17:21.220 --> 17:25.000
You're going to take the sprite renderer drag it like so.

17:25.540 --> 17:26.890
And this should be good.

17:26.890 --> 17:27.790
Let me see it.

17:27.790 --> 17:30.580
Let's apply overrides and let's go to play mode.

17:34.180 --> 17:39.340
I'm gonna run below the bee and bullet is flying out and it is chasing the player.

17:40.640 --> 17:41.270
Whoa!

17:41.980 --> 17:44.500
Yeah, yeah, that is quite fast.

17:45.330 --> 17:46.500
Let me try again.

17:53.560 --> 17:54.370
Cool, right?

17:54.430 --> 17:57.520
I think the lifetime is too long.

17:57.880 --> 18:06.970
So let's take the nib and let's do lifetime 1.5 and cool down maybe 0.75.

18:08.020 --> 18:08.980
Just for fun.

18:15.770 --> 18:16.220
Okay.

18:16.220 --> 18:19.340
That was quite fast with the disappearing.

18:20.900 --> 18:23.090
Why there are two bullets flew out.

18:24.820 --> 18:26.140
Now it's only one.

18:29.560 --> 18:31.840
Uh, maybe I was under the bed long enough.

18:31.840 --> 18:33.340
That's why I guess.

18:33.340 --> 18:33.850
Okay.

18:33.850 --> 18:34.180
It's fine.

18:34.180 --> 18:36.940
It's just so cool down and let's make it longer.

18:36.940 --> 18:40.480
Then let's do a cool down one, okay?

18:41.130 --> 18:43.050
Now a couple of other things.

18:43.050 --> 18:45.600
I would like to give this bullet a trail.

18:45.600 --> 18:49.680
And also I would like it to disappear in a pretty way.

18:49.800 --> 18:51.330
Now let's just.

18:53.160 --> 18:57.930
Go ahead and create effect trail.

18:58.540 --> 18:59.380
On this trail.

18:59.380 --> 19:01.030
We want to make it really slim.

19:01.030 --> 19:05.200
So like if you move it around now, you'll see how big is the trail.

19:05.800 --> 19:12.220
But if you change the width to something really small and also we can make a dot over here and make

19:12.220 --> 19:14.890
it thinner with the time.

19:14.980 --> 19:20.050
And also let's go to color and let's make it transparent with a time like that.

19:20.650 --> 19:21.400
This is good.

19:21.400 --> 19:23.710
Now it's going to look something like that.

19:23.740 --> 19:30.670
We only want to reduce the time over here to maybe, uh, point 75.

19:32.410 --> 19:32.890
Okay.

19:32.890 --> 19:34.570
So now we're going to have a trail.

19:34.570 --> 19:36.070
We only need to make it visible.

19:36.070 --> 19:40.660
So we're going to go to certain layer and do enemies minus one.

19:41.340 --> 19:44.070
All right, uh, let's try this.

19:44.070 --> 19:47.490
Let's apply overrides and let's go to play mode.

19:57.710 --> 20:01.730
And now, uh, something I did wrong.

20:02.920 --> 20:07.960
We need to go to trail and do transform zero zero.

20:07.960 --> 20:08.800
Okay.

20:09.130 --> 20:11.290
Let's apply overrides.

20:19.780 --> 20:22.510
And yeah, this should be good.

20:22.510 --> 20:26.110
Also, let's reduce speed so we can actually see what is happening.

20:26.110 --> 20:27.850
I'm going to do 4.5.

20:28.570 --> 20:30.460
Let's see the trail again.

20:33.170 --> 20:36.110
So there is the trail makes it pretty and nice.

20:36.140 --> 20:38.780
I'm going to increase a lifetime to three.

20:42.790 --> 20:43.150
Okay.

20:43.150 --> 20:45.730
There was a second bullet, and it's not supposed to be there.

20:45.730 --> 20:50.110
I guess we have animation on the loop, and that's why it is happening.

20:50.440 --> 20:52.570
I'm going to go to Asset animations.

20:52.570 --> 20:54.010
Enemies be.

20:54.010 --> 20:59.170
Let's take the be attack and let's uncheck loop time and let's do it for hit as well.

21:00.320 --> 21:00.710
Okay.

21:00.710 --> 21:02.390
This is good, I like it.

21:02.480 --> 21:03.530
Now what else?

21:03.530 --> 21:06.050
I want bullet to disappear in a pretty way.

21:06.050 --> 21:08.270
So I'm going to open the script.

21:09.060 --> 21:11.490
And I'm going to go to the root.

21:13.190 --> 21:14.180
Over here.

21:14.450 --> 21:17.660
Let me take the method over here.

21:17.660 --> 21:19.700
Actually, just this line of code.

21:19.700 --> 21:20.720
Copy this.

21:20.720 --> 21:22.010
Go to enemy bullet.

21:22.040 --> 21:22.430
Be.

21:24.760 --> 21:27.880
We're going to make Ondestroy method Ondestroy.

21:27.910 --> 21:29.440
We're going to create visual effect.

21:29.440 --> 21:31.240
And we just need this variable.

21:31.240 --> 21:33.790
So I'm going to go to fruit again.

21:35.180 --> 21:37.820
And I'm going to copy this.

21:37.850 --> 21:39.590
Go back to bullet B.

21:40.550 --> 21:42.560
Paste this in here.

21:45.590 --> 21:48.410
And is it destroyed on its own?

21:48.440 --> 21:49.460
I'm not sure.

21:50.220 --> 21:52.530
How do we destroy the visuals of this?

21:55.660 --> 21:56.770
Let me check.

21:56.980 --> 22:00.040
Asset prefab we fix.

22:00.040 --> 22:02.740
Pick up a fix and destroy me event.

22:02.740 --> 22:03.070
Okay.

22:03.070 --> 22:06.340
It is destroyed in the end of the animation, so it's fine.

22:06.610 --> 22:06.910
All right.

22:06.910 --> 22:07.900
So we're going to save this.

22:07.900 --> 22:12.550
And now it's going to create a visual effect when it is destroyed I kind of like it I only want to make

22:12.550 --> 22:13.090
it smaller.

22:13.090 --> 22:14.710
So I'm going to do new effects.

22:16.380 --> 22:18.660
Transform local scale.

22:20.060 --> 22:25.430
Equals to new vector 3.6 f 0.6 f 0.6 f.

22:25.550 --> 22:27.560
Okay, good.

22:30.660 --> 22:32.160
So we're done with the bullet.

22:32.160 --> 22:33.390
I think we can.

22:33.390 --> 22:35.340
Let me just show it to you once more.

22:35.340 --> 22:37.620
And I think we can close the script.

22:37.620 --> 22:38.940
We don't need it anymore.

22:38.970 --> 22:41.250
I'm going to close it, and we're going to work.

22:41.250 --> 22:42.420
And let's close the fruit.

22:42.420 --> 22:44.790
And we're going to work on the bee itself.

22:45.090 --> 22:48.900
Uh, what I want to do now is to improve movement of the bee.

22:49.110 --> 22:53.970
Let's assign pick up wave fix over here, and let's do apply overrides.

22:55.650 --> 22:56.010
Okay.

22:56.010 --> 22:57.630
Now I'm going to delete it.

22:57.630 --> 23:02.130
And let's talk about movement of the bee so I can place it over here for example.

23:02.130 --> 23:05.820
And it looks nice, but I want to make it more like a bee.

23:05.820 --> 23:10.590
I want to make it sort of buzzing around, uh, with a.

23:11.260 --> 23:12.220
Limb movement.

23:12.220 --> 23:12.760
Okay.

23:12.760 --> 23:15.310
I wanted to fly from left to right.

23:15.310 --> 23:16.480
That's what I want to do.

23:16.480 --> 23:17.860
So to do that.

23:20.390 --> 23:21.230
Woo woo.

23:21.230 --> 23:22.670
I like how bullets are flying.

23:22.670 --> 23:23.840
It looks pretty.

23:26.100 --> 23:29.190
Although just now I felt like it does not.

23:32.560 --> 23:35.080
Uh, let me try to increase lifetime.

23:38.870 --> 23:39.650
It's good.

23:39.650 --> 23:41.540
Just the lifetime was short.

23:42.910 --> 23:44.290
I kinda like it this way.

23:46.240 --> 23:46.630
Yeah.

23:46.630 --> 23:47.200
I'm sorry.

23:47.200 --> 23:53.200
So what I was saying, I want to make this be, like, just like that a little bit here and there.

23:53.200 --> 23:53.560
Right?

23:53.560 --> 23:54.670
That's what I want to do.

23:54.670 --> 23:56.440
And that's what we're going to do.

23:56.440 --> 23:58.630
It's a very simple thing to add.

23:58.690 --> 24:01.930
Let's go and open nib script.

24:04.580 --> 24:06.650
I'm going to make a list.

24:07.190 --> 24:10.160
Private list of vector three.

24:10.690 --> 24:16.300
We points, let's do equals to a new list of waypoints.

24:16.860 --> 24:17.400
Sorry.

24:17.400 --> 24:18.750
New list of vector three.

24:18.870 --> 24:22.560
Then we're going to need a private int way index.

24:25.010 --> 24:30.680
Similar to what we had on the B let's do using system collection generics.

24:31.040 --> 24:36.140
And we're going to open start method start or we have start method right.

24:36.140 --> 24:38.330
We can override it override start.

24:38.750 --> 24:45.800
And inside I want to do some sort of uh maybe we need some kind of private float.

24:47.040 --> 24:47.670
Offset.

24:47.670 --> 24:50.520
I'm going to make it equals to point 25 F.

24:50.520 --> 24:51.780
Maybe that's too big.

24:51.780 --> 24:54.600
I'll try and I'll make it visible so I can see it.

24:54.600 --> 24:55.650
Serialize field.

24:56.970 --> 24:59.670
Now, what are we going to do here on the waypoints?

24:59.670 --> 25:03.900
We're going to add our waypoint according to the position of the b.

25:03.900 --> 25:08.250
So if B is in the center first point will be here.

25:08.490 --> 25:10.380
Second point will be here.

25:10.740 --> 25:12.360
Third point will be here.

25:12.360 --> 25:14.100
Fourth point will be here.

25:14.100 --> 25:17.190
And because of that B is going to fly like that.

25:17.190 --> 25:19.140
And it's going to look like it's buzzing.

25:20.670 --> 25:21.600
That's what I want to do.

25:21.600 --> 25:25.800
Let's do it in some sort of simple way without overthinking it.

25:26.450 --> 25:28.190
I'm going to do waypoints.

25:28.370 --> 25:32.750
Add transform position plus new vector three.

25:32.750 --> 25:36.980
And for the x we want to add 0.25 f.

25:36.980 --> 25:41.720
So offset for the y we also want to add offset.

25:41.720 --> 25:44.120
And for the z we do need to add anything.

25:44.450 --> 25:45.980
Then I want to add another point.

25:45.980 --> 25:50.960
But this time we're going to have a same on the x and minus on the y.

25:50.990 --> 25:54.200
So first one will add point over here.

25:54.200 --> 25:56.570
Second will add point over here.

25:56.570 --> 26:03.050
If we pass both values as negative it's going to pass value over here I mean add position over here.

26:03.050 --> 26:05.360
And fourth one going to add value over here.

26:05.360 --> 26:11.750
Also if you want you can manually do it with the transforms just like we did with the Trapsoul okay.

26:11.750 --> 26:13.400
So I'm going to duplicate this.

26:15.020 --> 26:17.000
Do minus offset on the x.

26:17.000 --> 26:23.480
Actually, let's do both with the minus and then duplicate it and do positive on the y but minus on

26:23.480 --> 26:24.260
the x.

26:24.380 --> 26:25.970
Okay, that's what I want to do.

26:25.970 --> 26:29.420
Now we want to go to the update and make a method.

26:30.740 --> 26:33.920
Let's do a handle movement.

26:34.990 --> 26:35.650
Method.

26:38.430 --> 26:42.240
Inside of this method we're going to circulate between these positions.

26:42.240 --> 26:43.230
This is how it's going to be.

26:43.620 --> 26:45.810
Transform position equals to vector two.

26:45.810 --> 26:49.770
Move towards from a transform position to a waypoint.

26:50.370 --> 26:52.170
With our way index.

26:54.880 --> 26:57.130
And we're going to use speed.

26:57.460 --> 26:58.600
More speed.

26:59.310 --> 27:00.480
Multiplied by time.

27:00.630 --> 27:01.470
Delta time.

27:02.700 --> 27:03.180
Okay.

27:03.180 --> 27:08.730
And then if we are close enough again, we're going to just increase the index effector to the distance

27:09.000 --> 27:13.230
from transform.position to waypoint with an index.

27:15.780 --> 27:19.620
Is less than 0.1 F, and then.

27:22.830 --> 27:25.560
Then we're going to do way index plus plus.

27:25.590 --> 27:31.500
Also, we want to check if way index is bigger or equals than waypoints count.

27:32.280 --> 27:34.110
Uh, minus one.

27:34.930 --> 27:39.280
Then we index is equals to zero, right.

27:39.280 --> 27:41.920
Or we don't need minus one here I think we didn't need it.

27:42.310 --> 27:42.760
Okay.

27:42.760 --> 27:46.150
Let's save this and we're good to go.

27:52.760 --> 27:54.410
Can we wrap this into a method?

27:59.140 --> 28:00.520
Let's do method.

28:02.130 --> 28:03.780
Find target.

28:03.810 --> 28:06.690
If empty, something like that.

28:07.430 --> 28:08.480
Yeah, it should be good.

28:10.030 --> 28:12.670
Now, let me just go ahead and try this.

28:12.670 --> 28:14.320
You're going to go back to unity.

28:14.320 --> 28:16.300
We have offset of 25.

28:16.300 --> 28:17.560
And this might be too big.

28:17.560 --> 28:19.330
But I want to see it first.

28:19.330 --> 28:21.700
And let's give it more speed of six.

28:22.180 --> 28:23.650
Now let's go to play mode.

28:27.080 --> 28:32.030
And now we can see here more speed is too big, but other than that, it looks good.

28:32.240 --> 28:36.890
Now let's try move speed two and let's try less of the offset.

28:36.890 --> 28:39.260
Maybe, uh, point two.

28:44.130 --> 28:44.850
Oh, yeah.

28:44.850 --> 28:46.530
This looks a bit better, right?

28:46.650 --> 28:47.880
I think I like it.

28:47.880 --> 28:55.140
If you want, you can try to choose a random index instead of making it fly in circles, but I think

28:55.140 --> 28:57.090
I'm going to accept it as it is right now.

28:57.090 --> 28:58.110
I kind of like it.

28:59.030 --> 28:59.660
Yeah.

29:00.260 --> 29:04.880
Uh, and now it's gonna shoot bullets if you walk below it and you need to dodge them.

29:05.390 --> 29:07.010
Just increase the lifetime.

29:09.130 --> 29:10.990
Yeah, I think it's a fun mechanic.

29:12.920 --> 29:14.510
And then you need to kill it if you want.

29:14.540 --> 29:15.320
Boom.

29:15.920 --> 29:18.350
We need to stop movement if it died.

29:18.440 --> 29:20.180
Now let's go back to the script.

29:22.720 --> 29:23.680
Over here.

29:24.070 --> 29:27.370
If is dead, then return.

29:28.840 --> 29:29.590
Okay.

29:29.680 --> 29:30.520
Nice.

29:30.520 --> 29:31.750
Now let's close this.

29:31.750 --> 29:34.000
Let's go to Asset prefab.

29:35.320 --> 29:38.590
Let's go to enemies and let's make prefab out of this.

29:38.590 --> 29:41.290
So you can place multiple bees on the level.

29:42.130 --> 29:44.380
And we're good to go to the next video.

29:44.380 --> 29:46.420
Let me just try it.

29:48.680 --> 29:49.070
I'll wait.

29:49.070 --> 29:49.520
When?

29:50.180 --> 29:53.060
I want to give them a lifetime of.

29:53.930 --> 29:54.380
For.

30:01.150 --> 30:01.570
Oh, no.

30:01.570 --> 30:03.220
They fly in Synchronically.

30:03.940 --> 30:05.470
We need to fix it.

30:06.230 --> 30:07.520
As it looks silly.

30:09.150 --> 30:10.200
Oh, no.

30:15.710 --> 30:16.700
UN peu.

30:20.600 --> 30:20.870
You.

30:22.850 --> 30:23.300
Berlin.

30:25.650 --> 30:26.310
Okay.

30:26.310 --> 30:27.480
How can we do that?

30:28.580 --> 30:30.050
And let's go to the script.

30:33.380 --> 30:35.330
Let's make a method.

30:35.360 --> 30:37.220
Maybe we have it on the enemy.

30:37.820 --> 30:38.660
Allow movement.

30:38.660 --> 30:39.800
Something like that.

30:42.860 --> 30:44.060
Now I don't see it.

30:44.060 --> 30:44.810
Okay.

30:45.710 --> 30:47.030
I'm private void.

30:47.060 --> 30:48.950
Allow movement.

30:52.500 --> 30:56.490
It's going to do can move equals to true.

30:58.160 --> 31:08.390
Then on the movement method over here, if can move walls, then return and then go to the start method.

31:09.870 --> 31:11.400
Let's do invoke.

31:12.650 --> 31:13.850
Name of.

31:16.000 --> 31:17.500
Uh, allow movement.

31:18.040 --> 31:20.410
And I'm going to be a random value.

31:20.410 --> 31:25.510
So let's do float random value equals to random range.

31:27.560 --> 31:29.750
From zero to something like.

31:30.490 --> 31:31.240
I don't know.

31:32.480 --> 31:33.440
Point six.

31:34.280 --> 31:35.660
And this should be enough.

31:42.450 --> 31:43.560
Wait a second.

31:44.500 --> 31:45.700
Random value.

31:46.360 --> 31:48.790
Why does not allow me to use random?

31:53.220 --> 31:54.300
Okay.

31:57.270 --> 32:04.350
Now should be fine, and we can remove the system from here and remove this from here.

32:04.350 --> 32:05.700
And it should be good.

32:05.730 --> 32:11.340
Okay, now they're gonna fly with a random delay and I hope it's going to help.

32:11.340 --> 32:14.640
Also, let's take this and make a method.

32:16.770 --> 32:18.750
Create waypoints.

32:19.770 --> 32:21.540
Yes, a bit better.

32:23.740 --> 32:24.820
Now let's go to unity.

32:24.820 --> 32:25.930
Let's see them.

32:27.630 --> 32:29.580
And I do apply over rates.

32:38.380 --> 32:39.310
Didn't help.

32:40.240 --> 32:43.810
Because can move Boolean is true by default.

32:44.110 --> 32:45.280
I believe that's why.

32:49.690 --> 32:51.850
Let's do can move false.

32:52.580 --> 32:53.120
Now.

32:53.120 --> 32:55.010
It should work, I hope.

32:55.040 --> 32:56.180
Please work.

33:01.720 --> 33:02.290
Oh, yes.

33:02.290 --> 33:03.610
Now they flying randomly.

33:03.610 --> 33:04.180
Okay.

33:04.180 --> 33:06.880
Makes me dizzy a little bit, but it's fine, I guess.

33:07.360 --> 33:07.870
Oh.

33:14.940 --> 33:17.700
So you need to think how to bypass them.

33:32.670 --> 33:33.240
All right.

33:33.240 --> 33:34.320
This is cool.

33:35.010 --> 33:35.880
Also.

33:36.880 --> 33:41.170
Uh, the finish point is not working, but it's only because I'm in two players mode.

33:41.260 --> 33:43.600
It would be fine if you start game from the main menu.

33:44.080 --> 33:46.060
All right, I'll see you in the next video.

33:46.060 --> 33:46.900
Bye.
