WEBVTT

00:00.080 --> 00:02.080
Let's make our player shooting.

00:02.080 --> 00:04.920
So we're going to select our player GameObject in the hierarchy.

00:05.080 --> 00:08.440
And let's open up the player script by double clicking on it.

00:09.280 --> 00:16.600
So what we basically want to do, we just want to shoot basically means if we press star, if we click

00:16.760 --> 00:19.000
left mouse button, then we want to shoot.

00:19.440 --> 00:19.600
Uh.

00:19.640 --> 00:20.720
So we're going to do that.

00:20.720 --> 00:25.920
So let's open up our player script quickly and let's move over to this update function.

00:25.920 --> 00:28.080
Because we need to check every single frame.

00:28.080 --> 00:31.520
If we just uh, click left mouse button or not.

00:31.520 --> 00:35.600
So I'm going to do it in the bottom somewhere over here in update function.

00:35.600 --> 00:37.680
You can do it anywhere you like.

00:37.680 --> 00:39.680
It doesn't need to be in order.

00:40.040 --> 00:42.280
And we're going to check for some inputs.

00:42.280 --> 00:43.960
We're going to use this if condition.

00:43.960 --> 00:47.080
Then make first packet and some curly brackets.

00:47.440 --> 00:49.600
And what we want to check over here.

00:49.600 --> 00:52.560
We want to check for uh input.

00:52.560 --> 00:55.080
And we're going to check for left mouse button.

00:55.080 --> 00:58.920
So we're going to use this input uh dot get key function.

00:58.960 --> 01:05.530
Sorry dot get mouse button function, mouse button function and make this first brackets.

01:05.530 --> 01:13.770
So if you pass in this get mouse button mouse button down function one it's going to check for the right.

01:13.890 --> 01:17.250
Are you right click on mouse button.

01:17.250 --> 01:19.850
But we want to check for left mouse button.

01:19.850 --> 01:23.570
If you want to check for right mouse button then you can pass one.

01:23.570 --> 01:27.490
It's basically means that we're just clicking the right mouse button.

01:28.130 --> 01:30.090
Input dot get mouse button down.

01:30.090 --> 01:35.970
One basically means we just clicking the right mouse button, but I want to check for left mouse button.

01:35.970 --> 01:38.890
So that's why instead of one I'm going to pass zero.

01:38.930 --> 01:42.210
It's basically means we're just clicking the left mouse button.

01:42.210 --> 01:44.730
So what we want to do we just want to shoot.

01:44.730 --> 01:47.650
So we're going to make a another function for our shooting.

01:47.650 --> 01:49.770
So we're going to make it somewhere over here.

01:50.170 --> 01:52.530
And for function we're going to type void.

01:52.530 --> 01:55.530
And we have to name the function what we want to call it.

01:55.530 --> 02:00.970
So I'm going to call it something like shoot and then make first bracket and some curly brackets.

02:01.090 --> 02:03.810
And what we want to do inside this function.

02:03.810 --> 02:08.410
For now, let's print out a message in the console, say something like, uh, shoot.

02:08.450 --> 02:13.570
So we're going to type debug dot log for printing out message and then make first bracket.

02:13.570 --> 02:15.770
And then close that up with semicolon.

02:15.930 --> 02:22.370
And make sure you in make sure you just pass the string in this debug dot log function.

02:22.370 --> 02:27.490
So make first make quotation for string we need to type quotation.

02:27.490 --> 02:33.210
And we have to put a message that we really want to see underneath our console tab.

02:33.210 --> 02:37.810
So I'm going to say something like player shoot, player shoot.

02:37.850 --> 02:42.970
And what I'm going to do I'm gonna call this function over here.

02:42.970 --> 02:49.210
So if input dot get mouse button down zero basically means if we're clicking the left mouse button then

02:49.210 --> 02:51.930
what we want to do, we're going to call the shoot function.

02:51.930 --> 02:58.050
And what should function is really doing is just printing out a message in the console says player shoot

02:58.090 --> 02:59.410
as you can see.

02:59.410 --> 03:04.740
So let's call the function over here, which is shoot and make first bracket, then close that up with

03:04.740 --> 03:05.700
some my colon.

03:05.820 --> 03:10.220
So whenever we click the left mouse button this should function will call out.

03:10.220 --> 03:16.180
And this should function basically doing this thing which is printing out a message in the console says

03:16.180 --> 03:18.140
player should as you can see.

03:18.340 --> 03:21.700
And now we're going to press down Ctrl S to save our script.

03:21.700 --> 03:25.300
And let's move to unity and have a look on this.

03:26.260 --> 03:31.940
So whenever we're going to click the left mouse button that message should pop up right away.

03:34.860 --> 03:40.060
So just wait for a little moment and we're gonna have a look on this.

03:41.780 --> 03:45.780
And we're going to select our console tab in order to see our message.

03:46.100 --> 03:47.940
So I'm going to select my console tab.

03:47.940 --> 03:51.460
And let's click on this play button in the top to play our game.

03:51.860 --> 03:56.980
And whenever we're going to click the left mouse button that message just going to pop up right away

03:57.020 --> 03:58.660
says Player Shoot.

03:59.300 --> 04:00.940
So let's have a look on this.

04:00.940 --> 04:06.380
So if I click left mouse button, as you can see, as soon as we're clicking the left mouse button,

04:06.420 --> 04:12.860
the message in the console just getting pop up saying a player should, as you can see in the inspector.

04:12.860 --> 04:19.460
So I'm going to get out of play mode instead of printing out message what we really want to do, we

04:19.460 --> 04:20.860
just want to shoot.

04:21.100 --> 04:25.940
So let's double click on this message in order to open up in Visual Studio quickly.

04:26.500 --> 04:29.900
And instead of printing out message, we just want to shoot.

04:29.900 --> 04:36.420
So what we're gonna do, we're gonna shoot out a raycast from this player game object, top of this

04:36.420 --> 04:41.620
gun from this top of this gun of this player game object to the right direction.

04:41.860 --> 04:45.340
So whenever we click left mouse button, then we're gonna shoot.

04:45.420 --> 04:50.460
Basically we just want to shoot a raycast or a ray to the right side.

04:50.460 --> 04:51.700
So we're going to do that.

04:51.700 --> 04:54.660
So let's uh move to script.

04:54.660 --> 04:59.380
And over here instead of printing out message we're going to shoot out a ray.

04:59.420 --> 05:00.820
So we're going to use this function.

05:00.820 --> 05:04.910
It's called physics 2D, so use this physics 2D raycast.

05:05.070 --> 05:07.470
So this physics 2D dot raycast.

05:07.470 --> 05:09.070
It's going to shoot our ray.

05:09.270 --> 05:14.030
And as a first argument it's going to take the position from where you want to shoot out.

05:14.270 --> 05:20.670
So we're going to shoot out from the the top of this gun of this player game object to the right direction.

05:20.670 --> 05:23.310
And the second thing it's going to take the direction.

05:23.310 --> 05:26.350
And the third thing it's going to take the length of the ray.

05:26.390 --> 05:31.030
So we're going to also define the length of the array.

05:31.030 --> 05:32.150
We can simply say.

05:32.510 --> 05:37.870
And the fourth argument it's going to take the layer mask basically which game object we want to target.

05:37.870 --> 05:40.630
So we're going to target enemy game object for now.

05:40.630 --> 05:43.830
As you can see we don't have enemies at all.

05:43.990 --> 05:48.350
So for now we're gonna uh basically check with something else.

05:48.550 --> 05:52.830
Uh, you can simply say, so what we need, we need those variable.

05:52.830 --> 05:58.870
So let's make this, uh, for now, comment by double slash, and let's go to top of our class, because

05:58.870 --> 06:00.830
we need to gather those variables.

06:00.870 --> 06:05.080
We do know first thing we need a position where we want to create our.

06:05.440 --> 06:09.920
You can simply say the array or gonna shoot out our array.

06:10.040 --> 06:15.240
So let's make a public a public that will be transform.

06:15.240 --> 06:21.280
And we do know that this transform component is responsible for position rotation and scale.

06:21.280 --> 06:24.040
So that's why we because we need the position.

06:24.040 --> 06:26.840
And this transform gonna also have the position.

06:26.840 --> 06:29.480
So that is the position that is the thing.

06:29.520 --> 06:31.160
And we have to name and name it.

06:31.160 --> 06:34.800
So I'm going to call it something like shoot point or shoot position.

06:34.800 --> 06:36.080
We can simply call it.

06:36.080 --> 06:38.880
So I'm going to call it something like shoot point.

06:39.040 --> 06:43.200
And the second thing we need our direction in which direction.

06:43.200 --> 06:46.240
So we're going to shoot out the array to the right direction.

06:46.240 --> 06:49.320
So we don't need to put a variable for that.

06:49.320 --> 06:51.280
We're going to use vector two dot right.

06:51.280 --> 06:54.320
It's basically means we're going to shoot to the right direction.

06:54.320 --> 06:56.640
So we can just ignore that parameter.

06:56.640 --> 07:00.520
But we need as a third argument the length of the array.

07:00.640 --> 07:03.160
So we're going to define a length as well.

07:03.160 --> 07:06.440
So let's go to script and we're going to make another public.

07:06.440 --> 07:07.680
And that will be float.

07:07.680 --> 07:10.320
And we can call this one something like length.

07:10.320 --> 07:12.600
Or we can simply call it distance.

07:12.600 --> 07:19.640
And by default I'm going to give it a default parameter, something like uh something like five f or

07:19.800 --> 07:21.840
five unit distance.

07:21.840 --> 07:26.480
And the third argument we need layer mask basically which game object we want to target.

07:26.480 --> 07:29.160
So we're going to target our enemy game object.

07:29.160 --> 07:32.640
So we need to assign our enemy as a enemy layer.

07:32.640 --> 07:35.760
But for now let's uh type the variable.

07:35.760 --> 07:38.680
And we're going to take a look on that later.

07:38.920 --> 07:42.560
So we're gonna type public layer mask.

07:42.920 --> 07:47.000
And we can call this one something like attack layer or target Layer.

07:47.120 --> 07:50.760
Or we can simply call it what is enemy.

07:51.160 --> 07:52.680
What is enemy?

07:52.680 --> 07:53.840
Something like that.

07:54.000 --> 07:58.880
Or you can simply call it something like attack layer or target layer as well.

07:58.880 --> 08:01.040
It's basically totally up to you.

08:01.040 --> 08:03.130
And we're going to close that off up with semicolon.

08:03.130 --> 08:08.090
Let's press down Ctrl S to save our script and move over to unity.

08:08.090 --> 08:11.770
And we need to assign those variables one by one.

08:11.770 --> 08:16.570
So firstly we need to create a point from where we want to shoot out the array.

08:16.610 --> 08:20.810
So I'll create an empty game object to this player game object.

08:20.810 --> 08:24.850
And we're going to move it top of this gun of this player game object.

08:25.170 --> 08:31.490
So as soon as our player gets compiled we can see underneath our player script in the inspector should

08:31.490 --> 08:32.530
point distance.

08:32.530 --> 08:34.250
And this word is enemy.

08:34.490 --> 08:36.330
It just gets gets pop up.

08:36.330 --> 08:39.570
This this variable this variable just gets pop up.

08:39.570 --> 08:41.930
So we need to assign one by one.

08:41.930 --> 08:44.170
So let's create an empty game object.

08:44.170 --> 08:46.330
And we're going to move it top of this gun.

08:46.370 --> 08:51.050
So we're going to shoot out the array from that point or from that position.

08:51.050 --> 08:52.970
So let's select our player game object.

08:52.970 --> 08:54.250
Let's right click on it.

08:54.250 --> 08:56.650
Then create an empty game object.

08:56.650 --> 09:01.090
And you can call this game object to something like shoot point or fire point.

09:01.090 --> 09:03.900
But I'm going to call it something like shoot point.

09:04.700 --> 09:05.420
Shoot point.

09:05.420 --> 09:07.060
Then go over to Inspector.

09:07.340 --> 09:13.300
As Inspector, if you want to choose an icon, then click over here and I'm going to choose this gizmos

09:13.420 --> 09:15.860
and select the move tool from this scene view.

09:15.860 --> 09:17.940
And we're going to move it top of this gun.

09:18.180 --> 09:21.820
Something over here I guess this is going to be perfect.

09:23.540 --> 09:24.940
So perfect.

09:25.180 --> 09:27.980
And this is awesome.

09:28.860 --> 09:30.740
And this is okay.

09:31.140 --> 09:33.340
But you can just play around with this.

09:33.340 --> 09:35.500
And it's basically totally up to you.

09:35.980 --> 09:40.260
And now what we need to do now we need to select our player game object.

09:40.260 --> 09:45.060
And let's select this shoot point and drag it over to this shoot point field underneath your player

09:45.060 --> 09:46.500
skip and the distance.

09:46.500 --> 09:51.780
By default we set five basically means the length of the ray we can increase as well.

09:51.780 --> 09:54.140
So I'm going to set it to something like ten.

09:54.540 --> 09:55.980
And what is enemy.

09:55.980 --> 09:57.380
And it says nothing.

09:57.380 --> 09:59.740
For now let's create a test game object.

09:59.740 --> 10:04.100
And we're going to assign that game object as a enemy layer.

10:04.220 --> 10:05.100
So let's do that.

10:05.100 --> 10:06.540
So move over to hierarchy.

10:06.540 --> 10:08.580
Right click or hit this plus icon.

10:08.580 --> 10:12.020
Go to 2D object as sprite.

10:12.020 --> 10:13.900
And then we're going to choose this square.

10:14.100 --> 10:17.260
And I'm going to call this square to something like enemy.

10:17.460 --> 10:19.020
So I'm going to call it enemy.

10:19.180 --> 10:25.700
And make sure you attach colliders to this square or to this enemy game object as well.

10:25.700 --> 10:31.340
So it's going to detect our collision to do to do so let's click on this add component.

10:31.340 --> 10:36.260
And I'm going to add a component called Box Collider 2D for collision detection.

10:36.580 --> 10:38.740
And we added Box Collider 2D.

10:38.900 --> 10:41.980
And I'm going to move this one something over here.

10:42.140 --> 10:44.780
And in the Y I'm going to stretch a little bit.

10:44.780 --> 10:47.460
So let's go to Transform Scale in the Y.

10:47.500 --> 10:49.460
I'm going to set it to something like five.

10:49.820 --> 10:52.940
And this seems perfect as you can see.

10:53.940 --> 10:57.700
And we're going to assign this enemy game object as a enemy layer.

10:57.700 --> 10:59.300
So how you can do that.

10:59.620 --> 11:03.510
You need to select the game object first in which game object you want to do.

11:03.510 --> 11:06.310
So in our case, this anime is a game object.

11:06.310 --> 11:12.710
For now, we just, uh, use this square and make sure you just go to Inspector in the top right you

11:12.710 --> 11:15.030
can see layer and it says default.

11:15.030 --> 11:18.310
So just click there and then click on this add layer.

11:18.310 --> 11:20.350
And we need to create a new layer.

11:20.350 --> 11:22.870
So I'm gonna uh create a anime.

11:22.870 --> 11:27.470
So I'm going to type anime anime and hit enter to save it.

11:27.470 --> 11:30.030
And go back to that game object one more time.

11:30.030 --> 11:35.590
Basically select the game object in the hierarchy one more time, then go to Inspector and Layer.

11:35.590 --> 11:37.390
As you can see, it says default.

11:37.390 --> 11:43.310
So when I click there and we're going to choose this anime, now we assign it this anime as a anime

11:43.310 --> 11:45.710
layer, as you can see in the inspector.

11:45.710 --> 11:48.110
So make sure you just do that one more time.

11:48.150 --> 11:53.670
Basically, you need to select the game object and you need to assign with the layer which you recently

11:53.670 --> 11:54.190
name it.

11:54.190 --> 11:55.870
So make sure you just do that.

11:55.870 --> 11:58.430
And now we're going to select our player game object.

11:58.430 --> 11:59.950
And let's go to our player script.

11:59.950 --> 12:01.790
We can see what is anime.

12:01.790 --> 12:03.080
And it says nothing.

12:03.080 --> 12:10.440
So the array should be only detect this anime game object, or we only just want to damage this anime

12:10.480 --> 12:11.080
game object.

12:11.080 --> 12:11.880
So that's why.

12:12.040 --> 12:14.160
What is enemy or as a layer mask?

12:14.160 --> 12:15.800
We're going to choose our enemy.

12:15.840 --> 12:20.040
You can choose multiple at once as well by clicking.

12:20.040 --> 12:22.360
But, uh, I'm gonna choose this enemy.

12:22.400 --> 12:25.920
Or I just want to damage this enemy game object only.

12:25.920 --> 12:26.720
So that's why.

12:26.720 --> 12:28.280
What is enemy as a.

12:28.280 --> 12:31.520
I'm gonna choose enemy only, so it should be nothing.

12:31.520 --> 12:38.920
So you need to, uh, select the or select the layer in, uh, in which layer you just want to damage,

12:38.920 --> 12:41.480
or which game object you want to damage.

12:41.480 --> 12:46.080
But before it, make sure you assign that game object with some certain layer.

12:46.280 --> 12:48.480
And now we're going to select our player game object.

12:48.480 --> 12:51.440
Let's go to overrides and then click on Apply All.

12:51.480 --> 12:57.760
So the changes we made over here it's going to be saved into prefab of this player game object as well.

12:57.920 --> 13:03.640
So now let's open up our player script so that we only going to check for this enemy or this square

13:03.680 --> 13:04.360
game object.

13:04.360 --> 13:10.520
And we do know we assigned this square or this anime game object as a anime layer, and we have chosen

13:11.000 --> 13:13.440
underneath our player skip as well.

13:13.600 --> 13:15.480
So let's go to Skip now.

13:16.240 --> 13:20.280
And what we're going to do, we're going to move over to this physics 2D dot raycast.

13:20.280 --> 13:23.240
And let's remove those, uh, forward slashes.

13:23.240 --> 13:28.440
So the first thing it's going to take the suit position or from where we want to shoot out the ray.

13:28.440 --> 13:30.080
So I'm going to type this shoot point.

13:30.320 --> 13:34.840
Shoot point sorry shoot point dot position.

13:35.160 --> 13:41.440
Uh so which basically just moving over to this shoot point and then we just accessing the position.

13:41.440 --> 13:44.440
As you can see, we can see in the inspector.

13:44.840 --> 13:47.840
And the second thing it's going to take the direction.

13:47.840 --> 13:50.720
So we just want to shoot out in the right direction.

13:51.040 --> 13:51.920
Uh right direction.

13:51.920 --> 13:53.160
Something like that.

13:53.160 --> 13:55.360
So that's why we're going to pass transform Dot.

13:55.400 --> 13:55.720
Right.

13:55.720 --> 13:59.480
Or we can simply pass a vector to as well.

13:59.840 --> 14:01.960
Uh, you can think of it like this.

14:01.960 --> 14:06.690
So we are going to gonna use this new vector tool and make this first bracket.

14:06.690 --> 14:11.530
And we do know that this vector two is gonna have x axis and the y axis.

14:11.530 --> 14:15.210
So we don't want to shoot in the y axis at all.

14:15.210 --> 14:19.410
We want to only want to shoot to the right side or to the right.

14:19.450 --> 14:24.370
Or you can simply say in the X position we don't want to shoot it in the Y.

14:24.410 --> 14:27.370
So that's why in the Y we're going to put zero f.

14:27.530 --> 14:32.050
And we do want to shoot out in the right direction or in the x axis.

14:32.050 --> 14:35.490
So that's why we're going to put one f in the x axis.

14:35.490 --> 14:38.570
And if you put minus one then it's gonna move.

14:38.570 --> 14:44.130
Uh that should uh or the raycast will uh, are just gonna be in the left direction.

14:44.130 --> 14:46.410
But we don't want to do that.

14:46.410 --> 14:52.890
So that's why we just pass this positive one f or plus one f, you can simply say, or you can simply

14:52.890 --> 14:56.650
use this vector to vector to vector two dot.

14:56.690 --> 14:57.210
Right.

14:57.410 --> 15:01.530
Means, uh, the same thing x in the one and y in the zero.

15:01.570 --> 15:05.170
You can simply use that or you can use this one as well.

15:05.450 --> 15:07.850
Transform dot right.

15:07.890 --> 15:08.930
Transform dot right.

15:08.930 --> 15:12.370
Basically means, uh, the direction the player is facing.

15:12.490 --> 15:15.810
So as you can see, player is facing the right direction.

15:15.810 --> 15:19.650
So transform dot right basically means the direction the player is facing.

15:19.650 --> 15:23.090
So it's going to be somewhere like this to the right direction.

15:23.090 --> 15:24.850
So basically that is the thing.

15:24.850 --> 15:26.370
So I'm going to pass transform dot.

15:26.410 --> 15:26.890
Right.

15:26.890 --> 15:30.490
Or you can simply pass Vector2 dot right as well.

15:30.890 --> 15:36.090
And the third argument comma, it's going to take the distance or the length of the array.

15:36.090 --> 15:40.810
So I'm going to pass my distance and distance I set in Inspector.

15:41.130 --> 15:44.090
Uh as you can see ten in the inspector.

15:44.250 --> 15:49.410
So the length of the array and the fourth argument, it's going to take the layer mask or which game

15:49.450 --> 15:51.610
object we really want to target.

15:51.610 --> 15:55.530
So comma, as a fourth argument I'm going to pass what is enemy.

15:55.530 --> 15:57.410
And we do know what is enemy.

15:57.450 --> 16:02.770
We have chosen enemy game object or that enemy layer that we want to damage.

16:02.770 --> 16:09.940
So I'm going to pass My word is what is enemy and make sure you just close that up with semicolon.

16:10.220 --> 16:16.900
So this function physics 2D dot recap is gonna create the ray from this root point dot position in the

16:16.900 --> 16:17.820
right direction.

16:17.820 --> 16:19.860
With this much of length.

16:19.860 --> 16:22.980
And that ray is only gonna damage our enemy.

16:23.020 --> 16:24.100
As you can see.

16:24.140 --> 16:28.020
And we just pass what is enemy as a what is enemy?

16:28.060 --> 16:31.900
We only have chosen that enemy game object or that square.

16:32.220 --> 16:33.580
I as you seen.

16:34.500 --> 16:40.740
So this ray can be true or false, depending upon the ray is colliding with this enemy game object or

16:40.740 --> 16:41.140
not.

16:41.140 --> 16:44.700
So let's suppose that we just created the ray from this position.

16:44.700 --> 16:50.260
So if the ray collide with this enemy game object, then this function over here, it's gonna give us

16:50.300 --> 16:51.140
a true value.

16:51.180 --> 16:54.740
Or, or else it's going to give us a false value.

16:54.740 --> 17:00.580
So what we're going to do, we're going to store the result into a another raycast hit 2D parameter

17:00.700 --> 17:04.150
or a container or a variable you can call.

17:04.550 --> 17:05.550
So what are we going to do?

17:05.590 --> 17:07.310
We're going to type this raycast.

17:07.430 --> 17:11.910
Raycast hit 2D variable that basically type of the variable.

17:11.910 --> 17:13.950
So we do know this is a ray.

17:13.950 --> 17:16.590
So that's why we need to type this raycast hit 2D.

17:16.630 --> 17:21.310
And you have to name the variable or the parameter that you want to set with.

17:21.310 --> 17:23.630
So I'm going to call it something like hit info.

17:23.870 --> 17:28.910
Or you can simply call it call info or the hit information.

17:28.910 --> 17:31.110
And I'm going to set equal to this.

17:31.110 --> 17:37.830
So this hit info can be true or false depending upon if the ray is really colliding with this enemy

17:37.830 --> 17:38.870
GameObject or not.

17:38.910 --> 17:42.350
If it's then this, uh, just gonna give us a true value.

17:42.350 --> 17:48.190
So that's why this hit info is just gonna be a, uh, basically true because we directly sending it,

17:48.190 --> 17:54.510
as you can see, raycast hit 2D info, uh, sorry, raycast hit 2D, hit info equal to this.

17:54.750 --> 18:01.550
So if the ray is really gonna collide with that, uh, enemy game object, so this hit info gonna be

18:01.550 --> 18:03.350
true, or else it's gonna be false.

18:03.350 --> 18:09.470
So what we're going to do in the next, uh, in the next, we want to check if this heat info is true.

18:09.470 --> 18:13.870
Basically means if the ray is really, uh, colliding with this anime game object.

18:13.870 --> 18:19.350
So what we have to do, we need to damage this anime game object because the ray is just gonna collide

18:19.630 --> 18:21.750
with this anime game object.

18:22.550 --> 18:24.510
So we're going to check over here.

18:24.830 --> 18:29.910
Uh, so we're going to use this, uh, if condition, make first bracket and some curly brackets and

18:29.910 --> 18:33.830
what we want to check here, we want to check if hit info is true.

18:33.870 --> 18:39.190
Basically means the ray is really colliding with this enemy game object.

18:39.190 --> 18:42.710
So we're going to check if hit info is equals.

18:42.750 --> 18:48.150
Equals to true means the ray is really colliding with that, uh, anime game object.

18:48.150 --> 18:49.870
Or you can pass simply like this.

18:49.910 --> 18:56.350
If hit info, it basically means true and means our ray is colliding with that enemy game object.

18:56.790 --> 19:01.630
So what we want to do, we want to damage that enemy game object for now.

19:01.950 --> 19:04.880
Uh, later on we're going to give some help to our enemy.

19:04.920 --> 19:05.480
Game object.

19:05.480 --> 19:06.520
And we're going to subtract.

19:06.520 --> 19:06.960
For now.

19:06.960 --> 19:09.720
We're going to print out a message for printing out.

19:09.720 --> 19:12.480
We're going to type this debug dot log function.

19:12.480 --> 19:16.520
And this over here it's going to take the string or the message you want to see.

19:16.760 --> 19:21.000
So what we're going to do we're gonna go over to this hit info parameter.

19:21.000 --> 19:23.160
Basically we're gonna take this parameter.

19:23.160 --> 19:28.760
And by this parameter we're going to access the name of the game object the ray hit width.

19:28.760 --> 19:34.000
So if hit info is true basically means the ray really colliding with this enemy game object.

19:34.000 --> 19:38.560
So what we're gonna do, we're going to go we're gonna move over to this enemy game object, and we're

19:38.560 --> 19:41.880
going to access the name of this enemy game object.

19:41.880 --> 19:48.160
So we're going to move over to this hit info, as we do know that we're storing all of the information

19:48.160 --> 19:50.680
basically this ray into this info.

19:50.680 --> 19:58.640
So that's why we can extract any information about the ray with which we hit with the ray.

19:58.640 --> 20:03.720
So we can extract info like name, component, even the tag of the game object.

20:03.720 --> 20:06.050
So we're going to use this parameter to do that.

20:06.050 --> 20:09.530
So we're going to use this hit info transform dot name.

20:09.730 --> 20:13.610
So basically hit info dot transform basically means the array.

20:13.650 --> 20:16.810
Let's suppose the array collide with this enemy game object.

20:16.810 --> 20:18.330
So this enemy game object.

20:18.330 --> 20:24.930
So hit info dot transform basically means we're just going over to this uh game object which is enemy.

20:24.930 --> 20:30.930
So we just moving over to this enemy game object and then we accessing the transform of it, as you

20:30.930 --> 20:32.530
can see in the inspector.

20:32.530 --> 20:36.930
And by this transform we just accessing the name of the game object.

20:36.930 --> 20:42.570
So in our case we can see we just name it this square as enemy game object.

20:42.570 --> 20:48.570
So basically this hit info transform dot means the name of the enemy game object.

20:48.570 --> 20:50.410
And top of that what we're going to do.

20:50.810 --> 20:58.370
So make sure you just add this plus icon if you just want uh want to add any custom messages then make

20:58.370 --> 21:03.330
this a quotation and you can put whatever message just you want to say.

21:03.330 --> 21:08.730
So I'm going to pass octopus takes damage or something like that, and make sure you just close that

21:08.730 --> 21:10.090
up with semicolon.

21:10.090 --> 21:16.330
So hit info dot transform dot means name basically means we're just going over to this anime game object

21:16.330 --> 21:23.170
and we accessing the name so we can see we assign it this anime anime game object as an anime name.

21:23.170 --> 21:28.730
You can see in the inspector and top of that what we added a message, we added text image.

21:28.730 --> 21:30.250
So this is gonna be enemy.

21:30.250 --> 21:32.290
So enemy takes damage message.

21:32.290 --> 21:36.490
Just going to be pop up in the console right away once we hit.

21:36.530 --> 21:41.490
As you can see when we click the left mouse button, then we're calling the shoot function and shoot

21:41.490 --> 21:42.050
function.

21:42.050 --> 21:43.610
Firstly creating the array.

21:43.610 --> 21:48.130
And it's checking if the array is really colliding with this enemy game object or not.

21:48.130 --> 21:52.050
If it's then what we're doing, we're just printing out the message in the console.

21:52.730 --> 21:55.170
So this hit info dot transform dot main.

21:55.170 --> 21:57.410
Basically name is just gonna be enemy.

21:57.410 --> 21:58.570
So this is gonna be enemy.

21:58.570 --> 22:02.690
And on top of that we just add a custom message text damage.

22:02.690 --> 22:04.570
So enemy takes damage message.

22:04.570 --> 22:09.820
is just going to pop up right away, and we're going to press down control S in order to save our skip.

22:09.820 --> 22:11.180
And let's move to unity.

22:13.300 --> 22:19.140
So right after once we click our left mouse button, the rage is going to create from that short point,

22:19.140 --> 22:21.900
and it's going to shoot out to the right direction.

22:21.900 --> 22:27.820
And if the ray is really colliding with this enemy game object then in the console enemy takes damage

22:27.860 --> 22:30.020
message just going to pop up right away.

22:30.420 --> 22:34.540
So now if we click on this play button in the top and we can shoot.

22:34.540 --> 22:35.860
So I'm going to get out of play mode.

22:35.860 --> 22:39.660
So I'm going to click on this play mode in the top to get out of it.

22:39.700 --> 22:43.260
And I just want to make my player game object a little bit slow.

22:43.580 --> 22:45.940
Uh for testing purposes you can say.

22:45.940 --> 22:47.940
So I'm going to select my player game object.

22:47.980 --> 22:51.220
Let's go to Inspector then player skip.

22:51.220 --> 22:58.220
And I'm going to make the speed something like 2.5 to make it a little bit slower in order to checking

22:58.260 --> 22:59.340
purposes.

22:59.340 --> 23:03.100
So let's click on this play button now in the top.

23:04.940 --> 23:07.820
And let's have a look on this.

23:11.620 --> 23:16.380
So if I just click left mouse button as you can see the message.

23:16.380 --> 23:19.900
So I'm going to click on this pause button in the top to pause my game.

23:19.900 --> 23:24.620
And we can if we move over to console tab we can see anime takes damage.

23:24.700 --> 23:26.220
Just gets pop up y.

23:26.260 --> 23:30.060
Basically we're just going over to the game object the Ray hit with.

23:30.060 --> 23:33.660
So in our case we definitely gonna hit with that anime.

23:33.820 --> 23:35.620
So we just accessing the name.

23:35.620 --> 23:37.300
So the name is anime.

23:37.300 --> 23:41.540
And top of that we added a custom message says takes damage.

23:41.540 --> 23:44.620
So this just going to be anime enemy takes damage.

23:44.620 --> 23:48.020
So that's why the message in the console just gets pop up.

23:48.060 --> 23:49.700
Says anime takes damage.

23:49.740 --> 23:54.460
I hope you get the idea that how you can do it and I'm gonna get out of play mode.

23:54.460 --> 23:56.900
And also I'm gonna clear my console tab.

23:56.900 --> 24:02.500
So let's go to console tab and then click in this clear in the top left in console tab.

24:02.500 --> 24:05.900
You can see in order to clear all of the messages.
