WEBVTT

00:00.080 --> 00:01.240
Let's fix the box.

00:01.240 --> 00:02.800
Basically what we have to do.

00:02.800 --> 00:04.720
We need to open up our player script.

00:04.720 --> 00:06.080
So let's go to player script.

00:06.200 --> 00:10.040
And we're just checking if the script is uh, not equal.

00:10.200 --> 00:11.760
Equal equals to null.

00:11.800 --> 00:16.480
Then we typing return basically means this enemy to game object is totally that.

00:16.480 --> 00:22.280
We do know that enemy two script just gonna destroy with that enemy two game object as well.

00:22.280 --> 00:23.840
And we're checking over here.

00:23.840 --> 00:24.960
So I'm going to remove this.

00:25.000 --> 00:29.320
Instead of doing that we're going to check it over here as you can see.

00:29.320 --> 00:32.960
So we're just damaging our enemy two as well as enemy one.

00:32.960 --> 00:38.200
So before we damage we need to check if the script is attached to enemy game object or not.

00:38.200 --> 00:43.160
So we just, uh, damaging our enemy to game object, as you can see over here.

00:43.160 --> 00:48.400
So what, we basically want to check if we want to damage this enemy two game object.

00:48.680 --> 00:54.280
Uh, we do know we're just shooting out line renderer uh, line renderer line renderer.

00:54.280 --> 01:00.640
And once we delete this enemy two game object enemy two game object, we also destroying this anime

01:00.680 --> 01:02.120
two strip as well.

01:02.120 --> 01:08.280
We do know that if we destroy this anime two game object, it will destroy this anime two scrape as

01:08.280 --> 01:08.760
well.

01:08.760 --> 01:15.360
So what we basically need to do before we damage our enemy two game object or this anime one.

01:15.360 --> 01:21.160
We need to check if the enemy to skip is attached to this anime two game object or not before we just

01:21.160 --> 01:23.640
damage it to this anime game object.

01:23.640 --> 01:26.640
So what we will do, we will go to Skip and over here.

01:26.640 --> 01:32.440
As you can see, we just damaging right away if the ray just collided with this enemy to game object

01:32.440 --> 01:34.520
or not, we just damaging right away.

01:34.520 --> 01:40.640
So before we damage we need to check if the enemy two script is attached to this enemy two game object

01:40.640 --> 01:41.280
or not.

01:41.280 --> 01:46.680
And we can see in Inspector Anime two script is attached to this anime two game object.

01:46.680 --> 01:49.600
So before we damage we gonna check so we will check.

01:49.640 --> 01:53.600
If so we're going to use this hit info parameter, then transform.

01:53.600 --> 01:55.080
We're going to move over to that.

01:55.080 --> 01:59.090
And then we're going to use this get component in order to get the component.

01:59.090 --> 02:02.290
And the component we're looking for is our enemy two script.

02:02.290 --> 02:04.970
So we're going to pass enemy two and make first bracket.

02:04.970 --> 02:07.850
And we will check if it's not equal to null.

02:08.210 --> 02:11.210
If that is the case then we're going to make some curly brackets.

02:11.210 --> 02:15.770
So in that situation what we need to do we need to damage our enemy two game object.

02:15.770 --> 02:22.210
So what we basically have done over here hit info transform basically means the game object that collided

02:22.210 --> 02:22.690
with.

02:22.690 --> 02:25.770
So the rage definitely collide with this enemy.

02:26.410 --> 02:27.650
Enemy two game object.

02:27.650 --> 02:32.130
So basically we're just going over to this enemy two game object transform component.

02:32.130 --> 02:37.610
And by this transform we're just moving over to this enemy two script, as you can see in the Inspector.

02:37.610 --> 02:44.250
And we're checking if that enemy script, enemy two script is not equal to null basically means the

02:44.290 --> 02:47.690
enemy script is attached to this player game object.

02:47.810 --> 02:49.090
Sorry, sorry.

02:49.090 --> 02:50.890
I'm really apologize for it.

02:50.890 --> 02:55.170
So enemy two script is attached to this enemy two game object.

02:55.170 --> 03:01.610
As you can see, the script scrip is not equal to null means the scrip is really attached to this anime.

03:01.650 --> 03:01.930
Two.

03:01.970 --> 03:02.730
Game object.

03:02.730 --> 03:04.450
And we can see definitely.

03:04.610 --> 03:07.650
Indeed the anime two scrip is attached to this anime.

03:07.690 --> 03:07.850
Two.

03:07.890 --> 03:08.690
Game object.

03:08.690 --> 03:12.690
So we are now ready to damage this anime two game object.

03:12.690 --> 03:17.810
So that's why we're going to put this line of code by control X, and we're going to put it inside this

03:17.810 --> 03:19.690
curly brackets by Ctrl V.

03:19.850 --> 03:23.490
Then what we're doing we're just going over to hit info dot transform.

03:23.490 --> 03:26.770
So the array is just going to collide with this anime two game object.

03:26.770 --> 03:31.010
So hit info dot transform means this anime game object transform.

03:31.010 --> 03:34.450
And by this transform we're just going over to this anime two script.

03:34.450 --> 03:39.410
And we do know inside this anime two script, we just created a function called Take Damage.

03:39.410 --> 03:42.090
And we do know what that function really doing.

03:42.130 --> 03:47.330
It's just a it's just making our enemy two game object taking damage.

03:47.330 --> 03:48.810
So that is the thing we have.

03:48.850 --> 03:50.290
We just doing it.

03:50.290 --> 03:52.610
And also we're going to check for first enemy.

03:52.610 --> 03:53.970
So we're going to do the same thing.

03:53.970 --> 03:56.650
So we're going to use this hit info dot transform.

03:56.650 --> 04:01.250
And in order to extract information we're going to use this else if condition.

04:01.250 --> 04:02.290
Now we're going to check.

04:02.570 --> 04:06.610
So we're going to use the same uh, same line of code by Ctrl C.

04:06.650 --> 04:09.650
And we're going to paste it inside this bracket by Ctrl V.

04:09.770 --> 04:12.090
And now we're going to check if the enemy escape.

04:12.090 --> 04:14.370
So it's going to reference the first enemy.

04:14.410 --> 04:19.250
Or you can simply say the first enemy or the enemy one.

04:19.250 --> 04:21.250
And we're going to make some curly brackets.

04:21.450 --> 04:23.170
So we're just doing the same thing.

04:23.170 --> 04:25.930
Basically we're just looking for enemy script.

04:25.930 --> 04:31.370
And if it's not equal to null means this enemy script attached to our enemy game object.

04:31.370 --> 04:35.450
So in this moment we are ready to damage our enemy game object.

04:35.450 --> 04:37.370
So that's why we're going to put this line of code.

04:37.410 --> 04:40.290
Basically we damaging over here as you can see.

04:40.290 --> 04:42.850
So we're going to press down Ctrl X in order to cut.

04:42.850 --> 04:45.650
And we're going to paste it over here by Ctrl V.

04:45.690 --> 04:47.570
Then we're just going over to that game.

04:47.610 --> 04:49.050
Object means enemy.

04:49.090 --> 04:51.370
Then we're just moving over to enemy script.

04:51.370 --> 04:54.370
And from there we're just calling the Takedamage function.

04:54.420 --> 04:56.660
and this function just doing the right thing.

04:56.660 --> 05:02.940
And now what we're going to do inside the putting the or setting the second position where the ray hit

05:02.940 --> 05:03.340
width.

05:03.380 --> 05:07.140
We're going to put this line of code inside this curly brackets.

05:07.140 --> 05:09.860
So it's gonna collide with enemy two.

05:09.900 --> 05:16.660
Game object means our ray should be set over here because it's gonna collide with this enemy two game

05:16.700 --> 05:23.300
object and should it should not be passed through that this enemy two game object until and unless this

05:23.340 --> 05:25.260
enemy two game object dies.

05:25.260 --> 05:27.540
So that's why we're going to set the position as well.

05:27.620 --> 05:29.380
Means our second position, Ray.

05:29.540 --> 05:32.660
So we're gonna put it inside this curly brackets.

05:32.660 --> 05:35.100
So let's press down control X for cut.

05:35.260 --> 05:40.860
And we're going to paste it inside with first enemy as well by control V as well as we're going to put

05:40.860 --> 05:42.780
it over here control V.

05:42.980 --> 05:48.460
So basically we're just setting the second position of the line renderer component and hit info dot

05:48.460 --> 05:50.980
point basically means where the ray collided with.

05:51.020 --> 05:56.460
And we're doing inside this enemy anime one or this anime script means the first anime, then we're

05:56.460 --> 05:57.300
setting the position.

05:57.300 --> 06:00.260
Second position it info dot point over here.

06:00.260 --> 06:04.420
It's just going to reference the first anime the Ray hit with.

06:04.700 --> 06:09.620
So we're just taking that position and we're storing into the first one index.

06:09.620 --> 06:12.180
And we're just doing the same thing in anime two.

06:12.580 --> 06:18.980
So hit info dot point basically means over here the ray hit with that anime to game object.

06:18.980 --> 06:22.020
So if the ray hit with this anime two game object.

06:22.020 --> 06:26.460
So we're just taking that position and we're storing into this one index.

06:26.460 --> 06:32.900
If the ray just collided with the second anime, and if the ray collides with our first anime, then

06:32.900 --> 06:34.940
we're just setting that position.

06:34.940 --> 06:40.460
And over here just going to be hit info dot point right now just going to be the first anime.

06:40.740 --> 06:43.660
So basically it's going to collide with the first enemy.

06:43.660 --> 06:47.060
So that's why it's going to set the position of that line renderer.

06:47.060 --> 06:51.740
Second position uh, to that point where the ray collided with Lightweight.

06:52.020 --> 06:52.940
The first enemy.

06:53.100 --> 06:55.340
And basically we're just doing the same thing.

06:55.380 --> 07:01.540
And if you are still a little bit confused, then don't worry, I'm gonna have a video in the resources.

07:01.540 --> 07:07.300
If you just want to grab it more deeply, then you can check that video as well.

07:07.340 --> 07:13.700
I'm gonna have it in my resources so you can check that out if you just want to learn more deeply.

07:13.700 --> 07:15.700
So you can simply check that out.

07:16.100 --> 07:20.180
And now I'm gonna press down Ctrl X in order to save my script.

07:20.180 --> 07:22.420
And let's move over to unity by now.

07:22.540 --> 07:25.260
So by now the error should be gone.

07:25.900 --> 07:27.580
But let's have a look on that.

07:27.580 --> 07:32.020
So I'm going to press down Ctrl X sorry Ctrl S in order to save.

07:32.060 --> 07:33.500
And let's move to unity.

07:33.500 --> 07:39.100
So make sure you just save your script or else you're gonna get some weird errors in your console tab.

07:39.860 --> 07:45.980
Uh, so make sure you just press down Ctrl s, or you can just go over to top left file and then click

07:45.980 --> 07:47.460
on that save button.

07:47.460 --> 07:53.350
And now I'm going to click on this play button in the top to play our game and the error should be gone

07:53.350 --> 07:53.870
by now.

07:54.750 --> 07:58.070
So just wait for it to compile and then we can have a look on this.

07:58.430 --> 08:01.430
So let's attack on this, uh, enemy two game object.

08:01.670 --> 08:08.350
And uh, now we can see it just setting the position as well as the enemy two game object gets, uh,

08:08.350 --> 08:09.430
get destroyed.

08:09.430 --> 08:12.310
And also the messages get pop up in the console.

08:12.310 --> 08:18.470
Says enemy two died because once our enemy two game object or the enemy loses all of his health, then

08:18.470 --> 08:20.110
we're calling the die function.

08:20.110 --> 08:24.150
And inside that die function, we're just printing out a message in the console.

08:24.150 --> 08:28.350
Says the enemy died, uh, with corresponding name.

08:28.350 --> 08:29.870
So I'm going to get out of play mode.

08:29.870 --> 08:31.230
And that is the cool thing.

08:31.230 --> 08:32.630
I hope you get the idea.

08:32.750 --> 08:35.950
And I'm going to press down Ctrl s to set my project.

08:35.950 --> 08:41.110
And also let's select the enemy two game object overrides and we're going to click on this Apply all.

08:41.150 --> 08:47.150
So if you change anything in the inspector it's going to be saved into this enemy GameObject prefab

08:47.190 --> 08:47.950
as well.

08:48.470 --> 08:50.070
So basically that is the thing.
