WEBVTT

00:00.080 --> 00:04.800
Let's keep some health amount to our enemy game object, then we're gonna damage it.

00:04.960 --> 00:09.360
So let's select our enemy one game object, and let's open up the.

00:10.080 --> 00:15.200
Select the enemy one GameObject in the hierarchy first, and then open up the script by double clicking

00:15.200 --> 00:15.960
on it.

00:15.960 --> 00:21.200
So what we need, we need to give some health amount to our enemy game object.

00:21.200 --> 00:25.720
So I'm gonna go to top of our class and let's declare a variable.

00:25.720 --> 00:29.240
And that will be in like whole number 01234.

00:29.360 --> 00:32.680
So we're going to make a public and that will be int.

00:32.680 --> 00:35.480
And we're going to call it something like max health.

00:35.840 --> 00:39.880
And by default you can give any value that you would like to go with.

00:39.880 --> 00:42.200
Or you can just close that off with semicolon.

00:42.200 --> 00:46.000
And later on you can adjust in the inspector as well.

00:46.000 --> 00:49.120
So I'm going to give a default value something like three unit.

00:49.320 --> 00:52.960
And let's make a function in order to take damage.

00:52.960 --> 00:55.640
So we're going to make it somewhere in the bottom.

00:55.640 --> 00:57.600
And we're going to make this function public.

00:57.600 --> 00:57.920
Why.

00:57.960 --> 01:02.960
Because we're going to call this function through another script or another C sharp class.

01:02.960 --> 01:05.360
So that's why we're going to make this function public.

01:05.360 --> 01:06.760
So let's make it public.

01:06.760 --> 01:08.600
And for function we're going to type void.

01:08.640 --> 01:11.280
And we have to name the function what we want to name it.

01:11.280 --> 01:14.760
So we're going to call it something like take a damage.

01:14.760 --> 01:18.080
And we're going to pass first bracket and some curly brackets.

01:18.240 --> 01:22.240
And this function over here it's going to take an argument.

01:22.240 --> 01:28.840
So basically what you have to do you need to write in between this first bracket int that will be int.

01:28.840 --> 01:31.520
And we can call that one something like damage.

01:31.760 --> 01:37.480
And we can later on we can replace this number with any number that we would like to go with something

01:37.480 --> 01:40.400
like one, two, three, four like that.

01:40.400 --> 01:42.000
So now what we're going to do.

01:42.480 --> 01:45.960
So as you can see we created a Maxhealth parameter.

01:46.000 --> 01:48.320
Now we are ready to subtract that.

01:48.320 --> 01:51.160
So we're going to do it inside this takedamage function.

01:51.160 --> 01:52.120
So we're going to subtract.

01:52.120 --> 01:58.450
So max health in order to subtract we're going to use this minus equal and the amount that we want to

01:58.490 --> 01:58.850
subtract.

01:58.850 --> 02:01.010
So we're going to pass this damage parameter.

02:01.010 --> 02:03.330
And let's close that up with some my column.

02:03.330 --> 02:07.290
So let's call uh let's suppose we call this function for the first time.

02:07.290 --> 02:09.530
So the max health by default we set three.

02:09.570 --> 02:11.370
As you can see over here.

02:11.370 --> 02:12.610
So this is going to be three.

02:12.610 --> 02:17.250
And let's suppose as a damage parameter you just pass a one later on.

02:17.250 --> 02:18.650
So this is going to be one.

02:18.650 --> 02:19.810
So this is three.

02:19.810 --> 02:21.770
So three minus one is going to be two.

02:21.930 --> 02:24.850
And if you call this takedamage function one more time.

02:24.850 --> 02:26.850
So then now the max health is two.

02:26.890 --> 02:29.010
So two minus one is just going to be one.

02:29.010 --> 02:32.170
And if we call this takedamage function for the third time.

02:32.170 --> 02:34.410
So the max health is already now one.

02:34.410 --> 02:37.530
So one minus one is just going to be zero right away.

02:37.690 --> 02:40.450
So somehow this max health will reach zero.

02:40.610 --> 02:46.570
So uh, zero then what we have to do, we need to destroy our enemy game object right away.

02:46.570 --> 02:50.050
But before we destroy, we need to stop doing this thing.

02:50.050 --> 02:54.770
So let's suppose the max health is already zero of this enemy game object.

02:54.770 --> 02:57.170
And then we call this max health function.

02:57.170 --> 03:01.650
So the max health is now zero, and so zero minus one is just going to be minus one.

03:01.650 --> 03:03.650
So it will move over to negative value.

03:03.650 --> 03:05.530
So we need to stop doing it.

03:05.530 --> 03:10.930
So before we subtract one we need to check if the max health is already zero or not.

03:10.930 --> 03:18.410
So we're going to check if max health is less than or equal to zero means we need to stop doing this

03:18.810 --> 03:19.650
doing these things.

03:19.650 --> 03:21.690
So we're going to type some curly brackets.

03:21.890 --> 03:24.010
And in this brackets what we're going to do.

03:24.010 --> 03:27.890
We're going to type this return and then close that output semicolon.

03:27.890 --> 03:31.890
So after return whatever you're going to do it's not going to be executed.

03:31.890 --> 03:33.690
So the max cell let's suppose zero.

03:33.690 --> 03:36.130
So this condition is just going to be true right away.

03:36.130 --> 03:37.850
And we just type in return.

03:37.850 --> 03:40.210
And after return whatever we're going to do.

03:40.250 --> 03:42.410
This line of code will not be executed.

03:42.410 --> 03:47.370
Means the max health will start at zero once the max health reaches zero.

03:47.530 --> 03:53.450
As you can see, we're doing we basically checking the max cell is already less than or equal to zero.

03:53.530 --> 03:58.410
Then we typing return And we do know after return whatever we're going to do.

03:58.450 --> 04:00.090
It's not going to be executed.

04:00.090 --> 04:02.810
And let's also make a die function.

04:03.530 --> 04:05.850
But before we do, let's save our script.

04:05.850 --> 04:08.090
And we also need to call the function.

04:08.090 --> 04:10.450
So we just made this Takedamage function.

04:10.450 --> 04:14.930
And in order to take damage we also need to call that Takedamage function.

04:14.930 --> 04:19.210
But where are we going to do where we're going to call that function?

04:19.210 --> 04:23.370
Once this player game object shoot on this enemy game object.

04:23.370 --> 04:29.290
At that moment, we're going to call the uh, at that moment we we will call that function, which is

04:29.290 --> 04:31.410
the take damage as you seen.

04:33.410 --> 04:35.090
So just wait for to compile.

04:35.850 --> 04:37.050
Now it's done.

04:37.050 --> 04:42.690
So let's, uh, let's select our player game object where we're shooting, and let's open up the player

04:42.690 --> 04:44.690
script by double click on it.

04:44.690 --> 04:48.050
So as you can see we're just printing out a message.

04:48.250 --> 04:50.130
Uh, it says takes damage.

04:50.250 --> 04:52.250
Uh, basically enemy takes damage.

04:52.250 --> 04:56.450
But instead of doing this, we really want to damage our enemy.

04:56.730 --> 04:58.410
Sorry enemy game object.

04:58.410 --> 04:59.730
So we're going to do that.

04:59.730 --> 05:05.770
So what we will do we're going to use this hit info parameter in order to extract info whatever the

05:05.770 --> 05:07.010
ray hit with.

05:07.010 --> 05:09.130
So we're going to we're going to get the component.

05:09.130 --> 05:14.650
Firstly we will go over to transform sorry transform then Game Object.

05:14.810 --> 05:17.050
Then we're going to use this get component.

05:17.690 --> 05:21.290
And in this component make arrows into these arrows.

05:21.290 --> 05:25.290
We need to pass the script name that we really want to access.

05:25.290 --> 05:28.250
So in our case we're going to access the enemy script.

05:28.250 --> 05:31.130
So we're going to type enemy and then make first bracket.

05:31.130 --> 05:35.050
And over there we created the Takedamage function as used in.

05:35.050 --> 05:36.770
So we're going to call the function over here.

05:36.770 --> 05:41.970
So let's call it dot take damage and make first bracket and then close that up with semicolon.

05:41.970 --> 05:43.970
So this take damage right over here.

05:43.970 --> 05:47.010
It's going to take an argument as you can see.

05:47.010 --> 05:48.930
So we need to give a argument.

05:49.450 --> 05:51.170
So I'm going to pass one.

05:51.170 --> 05:52.540
So if we pass one.

05:52.540 --> 05:55.020
So every single time it's going to subtract one.

05:55.020 --> 05:58.580
And let's suppose you just pass two instead of one.

05:58.580 --> 06:02.980
Then the max health will gradually, uh gonna go down.

06:02.980 --> 06:09.180
And if you just pass three right away then the max, uh, then the our enemy game object will, uh,

06:09.220 --> 06:13.340
lose right away once we shoot on that enemy game object.

06:13.500 --> 06:15.100
But I'm gonna go with one.

06:15.100 --> 06:18.220
So that's why I just want to subtract every single time.

06:18.220 --> 06:19.180
One unit.

06:19.180 --> 06:22.300
If we just shoot on that enemy game object.

06:22.620 --> 06:26.380
Uh, so we're gonna press down control S in order to save our skip.

06:26.380 --> 06:28.380
And now let's move over to unity.

06:28.700 --> 06:34.060
So this hit info gets to once the ray collided with that enemy game object.

06:34.060 --> 06:39.900
Then what we're doing, we're just going hit dot, hit info dot transform dot game object basically

06:39.900 --> 06:42.300
means the game object that ray hit with.

06:42.300 --> 06:46.300
So the ray just definitely gonna hit with this enemy game object.

06:46.300 --> 06:51.660
So basically we're just going over to this enemy game object transform we can see in the inspector.

06:51.660 --> 06:57.380
And we by this transform which is accessing the whole, uh, whole this enemy game object.

06:57.380 --> 07:02.860
And then we're just going over to this enemy script, and then we're just calling this Takedamage function,

07:02.860 --> 07:05.940
and we don't know what Takedamage function is really doing.

07:05.940 --> 07:07.220
It's just subtracting.

07:07.220 --> 07:14.300
So if we call this damage function third time, and the max health of that enemy game object will gradually

07:14.300 --> 07:18.100
down, and we also need to destroy our enemy GameObject.

07:18.100 --> 07:20.940
But before we do, let's have a look on this.

07:20.940 --> 07:24.300
So I'm going to select my enemy one GameObject in the hierarchy.

07:24.300 --> 07:26.620
And let's click on this play button in the top.

07:26.620 --> 07:28.740
In order to play our game.

07:28.740 --> 07:35.580
You will see once we just click on this enemy game object three times, this enemy is just gonna lose

07:35.580 --> 07:36.860
all of his health.

07:36.860 --> 07:40.820
So first time sorry, we need to get a little bit closer.

07:41.340 --> 07:42.700
So we're going to shoot.

07:43.420 --> 07:44.540
So let's click.

07:44.580 --> 07:50.740
As you can see, as soon as we shoot two times we can see Max health is now one and if I just shoot

07:50.780 --> 07:55.820
third time we can see the max health is now zero of this enemy GameObject.

07:55.820 --> 07:57.300
So what we need to do.

07:57.300 --> 07:58.980
So let's get out of play mode.

07:58.980 --> 08:06.380
So the once the uh, reach of this maxhealth, basically, once our max health of this enemy GameObject

08:06.380 --> 08:10.340
reaches zero, then we want to destroy this enemy GameObject.

08:10.340 --> 08:14.540
But before we destroy, let's make a die function in order to do that.

08:14.540 --> 08:18.900
So let's go to enemy script and we're going to make the die function in the bottom.

08:18.900 --> 08:20.740
And it doesn't need to be public.

08:20.740 --> 08:23.460
Basically this function doesn't need to be public.

08:23.460 --> 08:28.300
Instead we can make it private, but we can simply type type void.

08:28.340 --> 08:34.700
So if we just don't assign with something like private right in front of this void or public, it will

08:34.700 --> 08:41.820
be marked as a private or just gonna declare itself automatically a private function.

08:41.820 --> 08:44.380
And we have to name the function what we want to name it.

08:44.380 --> 08:49.060
So I'm going to call it something like die make first bracket and some curly brackets.

08:49.100 --> 08:51.180
For now, we're gonna print out a message.

08:51.180 --> 08:54.380
I don't want to destroy my enemy game object right away.

08:54.580 --> 09:00.860
So that's why what I'm going to do, I'm going to type, uh, basically debug dot log, debug dot log

09:00.860 --> 09:02.780
in order to print out a message.

09:02.780 --> 09:05.140
And I'm going to say something like enemy.

09:05.460 --> 09:10.620
Or we can simply pass this dot transform dot name.

09:10.620 --> 09:13.820
And top of that I am going to add a custom message.

09:13.820 --> 09:15.820
So plus and make quotation.

09:15.820 --> 09:22.580
And you can just add top of that custom message that you really want to see something like uh tight.

09:22.940 --> 09:25.100
And let's close that up with semicolon.

09:25.500 --> 09:30.420
So this this dot transform dot name basically is just referring itself.

09:30.420 --> 09:34.180
This just referencing this enemy game object itself.

09:34.180 --> 09:39.220
And then we're just moving over to this transform component of this enemy game object.

09:39.220 --> 09:43.980
And then by this transform component, we just accessing the name of the game object.

09:43.980 --> 09:49.870
And we can see in Inspector the name is anime one, so this is going to be anime one.

09:50.190 --> 09:53.630
The name and top of that we added a custom message.

09:53.830 --> 09:55.110
Style means anime.

09:55.150 --> 10:01.790
One type message is going to pop up in the console, so we also need to call this take this type function.

10:02.190 --> 10:05.950
We just made this die function, but we never call it calling it.

10:05.950 --> 10:12.110
So this line of code will not be executed means we're not going to able to see this message once we

10:12.110 --> 10:13.990
loses all of our help.

10:13.990 --> 10:17.310
So what we will do, we will move over to this update function.

10:17.310 --> 10:20.710
And we do know that update function runs every single frame.

10:20.710 --> 10:26.670
So every single frame we're going to keep track of how much health this anime game object kernel currently

10:26.670 --> 10:27.030
have.

10:27.070 --> 10:33.390
And if the max health of our anime game object is already zero, then we're going to call this die function.

10:33.390 --> 10:39.030
And what this function is doing is just printing out a message in the console says anime one died,

10:39.070 --> 10:40.270
as you can see.

10:40.270 --> 10:41.270
So let's call it.

10:41.270 --> 10:46.510
So I'm going to move over to this update function and top of this update function, I'm going to check

10:46.550 --> 10:49.950
if I make first bracket and some curly brackets.

10:51.190 --> 10:52.950
So what we want to check over here.

10:52.950 --> 10:57.030
We want to check the Maxhealth of our enemy GameObject.

10:57.030 --> 11:04.590
So I'm going to check if Maxhealth is lesser than or equal to zero means the max health of our enemy

11:04.590 --> 11:08.750
GameObject, or this enemy GameObject just loses all of his health.

11:08.750 --> 11:14.510
So we're checking if the max health is lesser than or equal to zero means we don't have any health,

11:14.670 --> 11:15.750
then what we have to do?

11:15.790 --> 11:18.390
We need to call this type function and die function.

11:18.390 --> 11:23.750
Just going to do the best thing which which is just going to print out the message in the console says

11:23.790 --> 11:24.830
enemy one died.

11:24.830 --> 11:26.710
So let's call the function over here.

11:26.750 --> 11:30.870
Once we reach a max health of this enemy GameObject zero.

11:30.870 --> 11:37.750
So let's call the die function uh die function and make first bracket and then close that up with semicolon.

11:37.750 --> 11:41.950
And we're going to press down control S in order to save our script.

11:41.950 --> 11:43.630
And let's move to unity now.

11:43.990 --> 11:49.950
So once this many enemy GameObject just gonna lose all of his health, that die function just gonna

11:49.950 --> 11:54.710
call right away and we don't know what we doing inside that die function.

11:54.710 --> 11:59.270
We basically printing out a message in the console says enemy one died.

11:59.310 --> 12:00.190
So let's have a look.

12:00.190 --> 12:04.790
So I'm going to click on this play button in the top in order to see that.

12:08.510 --> 12:10.350
So just wait for it to compile.

12:12.030 --> 12:17.550
And so let's basically attack on this enemy game object three times.

12:17.550 --> 12:22.190
You will see once this enemy game object just gonna lose all of his health.

12:22.230 --> 12:27.470
As you can see, as soon as the max health of this enemy game object, I'm going to click on this pause

12:27.470 --> 12:30.510
button in the top in order to pause my game.

12:30.510 --> 12:35.070
So the max health we can see in in this enemy game object is now zero.

12:35.230 --> 12:41.310
And if we move over to console tab, we can see enemy one died message just getting pop up every single

12:41.310 --> 12:41.750
time.

12:41.790 --> 12:45.470
because this anime one game object just loses all of his hell.

12:45.470 --> 12:51.030
And we do know once we lose it, we're just calling the die function and die function just doing the

12:51.030 --> 12:51.830
rest thing.

12:51.830 --> 12:58.110
So let's get out of play mode instead of printing out message, we just want to destroy our enemy game

12:58.150 --> 12:58.630
object.

12:58.630 --> 13:02.550
So let's double click on this message in order to move that line of code.

13:02.550 --> 13:05.950
Or we can simply move over to our anime script.

13:05.950 --> 13:07.470
So let's move to die function.

13:07.470 --> 13:12.750
As you can see, we just printing out the message over here and after printing out message, I just

13:12.750 --> 13:15.670
want to destroy my enemy game object.

13:15.670 --> 13:19.230
And in order to destroy, we're going to use this destroy function.

13:19.230 --> 13:23.270
And this destroy function, it's going to take the game object you want to destroy.

13:23.270 --> 13:27.870
So in our case we're going to pass this dot game object basically means itself.

13:28.150 --> 13:30.710
And then we're going to close that up with semicolon.

13:30.710 --> 13:32.670
Firstly we're printing out message.

13:32.670 --> 13:36.310
And after that we're just destroying the enemy game object right away.

13:36.470 --> 13:43.240
And if you just want to put a specific time and after that amount of time, you just want to destroy.

13:43.400 --> 13:48.080
Then as a second argument, comma, you can specify the time as well.

13:48.080 --> 13:51.000
But I'm going to destroy my enemy game object right away.

13:51.000 --> 13:58.880
So that's why as a second argument, I'm not gonna give any value or any time or after that amount of

13:58.880 --> 14:00.440
time, I just want to destroy.

14:00.480 --> 14:03.440
I just want to destroy my enemy game object right away.

14:03.440 --> 14:06.160
So that's why this game object, I just pass.

14:06.200 --> 14:11.520
And as a second argument, I haven't decided to put it over here.

14:11.520 --> 14:14.360
So the enemy game object just gonna destroy right away.

14:14.360 --> 14:18.480
And we're going to press down control S one more time in order to save our script.

14:18.480 --> 14:19.960
And let's move to unity.

14:24.840 --> 14:30.960
So once this enemy game object loses all of his health, you will see this enemy game object just gonna

14:31.000 --> 14:32.360
destroy itself.

14:32.480 --> 14:34.120
So let's click on this play button.

14:34.120 --> 14:38.040
But before I do, I'm going to make my player speed a little bit fast.

14:38.040 --> 14:40.720
So I'm going to select my player GameObject in the hierarchy.

14:40.920 --> 14:44.280
And I'm going to make the speed something like 1.5.

14:44.400 --> 14:46.520
And now let's click on this play button.

14:46.520 --> 14:48.760
We will see this player GameObject.

14:48.800 --> 14:56.640
Just going to move a little bit faster in the right direction because we just increased up our speed.

14:56.640 --> 15:00.600
As you can see in the inspector underneath our player script.

15:01.000 --> 15:03.080
So let's get rid attack.

15:03.720 --> 15:09.960
As you can see, as soon as our enemy GameObject loses all of its health, we can see this enemy GameObject

15:09.960 --> 15:12.520
just loses all of his all of his health.

15:12.520 --> 15:14.200
But before it destroy it.

15:14.200 --> 15:18.040
Also print out a message in the console says enemy one died.

15:18.080 --> 15:19.160
As you can see.

15:19.200 --> 15:21.560
And after that it just destroyed itself.

15:21.680 --> 15:23.320
So let's get out of play mode.

15:23.360 --> 15:25.680
And I want what I want to do.

15:25.720 --> 15:33.000
I just want to, uh, basically, uh, I want to show up an explosion effect before this enemy GameObject

15:33.000 --> 15:33.520
dies.

15:33.640 --> 15:37.280
So we're going to do that, uh, for in order to do, I'm going to move.

15:38.080 --> 15:43.600
Move over to my project tab, then assets and assets and then sprites folder.

15:44.480 --> 15:46.120
Sprites folder.

15:46.160 --> 15:49.960
I have it and I'm going to move over to my explosion folder.

15:50.240 --> 15:54.520
So I need to take a look if there is explosion or not.

15:58.200 --> 16:06.680
Uh, I can not able to see explosion or we can simply type over here as well.

16:07.000 --> 16:08.160
Explosion.

16:08.640 --> 16:10.120
And I don't see.

16:10.120 --> 16:13.200
So we need to drag the explosion sprites first.

16:13.840 --> 16:22.200
So what I'm gonna do, I'm gonna open up my file manager and then local Dixie, and then I'm gonna move

16:22.200 --> 16:25.200
over to my this.

16:27.320 --> 16:29.960
And this built.

16:31.920 --> 16:40.840
Sorry to to to to to Do assets sprites, explosion.

16:40.840 --> 16:43.400
So I have explosion sprites over here.

16:43.400 --> 16:47.160
So I'm going to drag in my project in this unity project.

16:47.440 --> 16:53.520
Uh, I'm going to make a sub folder in this sprite folder by right clicking create folder.

16:53.760 --> 16:58.360
And I'm going to call this folder to something like sorry I'm going to right click on it.

16:58.360 --> 16:59.960
Let's click on this rename.

17:00.480 --> 17:02.960
And I'm going to call it explosion.

17:03.280 --> 17:07.440
And I'm going to drag all of the explosion over here in this folder.

17:07.440 --> 17:10.240
So let's select them and drag it over to this folder.

17:10.480 --> 17:17.240
And unity just going to take a moment in order to uh import all of all of these assets.

17:17.360 --> 17:18.600
So now it's done.

17:18.920 --> 17:22.880
So what I want to do I want to show the show of the explosion.

17:22.880 --> 17:29.560
So I'm going to move over to my explosion folder, then this and let's select this sprite.

17:31.600 --> 17:37.970
So we need to find a perfect sprites, so this one seems perfect to me.

17:37.970 --> 17:40.410
So I'm going to select my that sprites.

17:40.450 --> 17:44.730
Let's go to uh, basically this sprite editor pixel per unit.

17:44.730 --> 17:51.610
We're going to make it 16 filter mode to point no filter and then click apply and Sprite editor top

17:51.610 --> 17:52.530
left slice.

17:52.530 --> 17:57.530
Select automatic to create pixel count and count how many columns and rows it has.

17:57.530 --> 18:01.610
So four eight, 12.

18:01.610 --> 18:05.290
So we're going to put 12 columns and one row.

18:06.330 --> 18:09.050
Click slice apply and it's done.

18:09.050 --> 18:12.410
So let's click on this arrow and I'm going to select my first sprite.

18:12.410 --> 18:15.970
Let's drag it over to this scene view or into this hierarchy.

18:16.130 --> 18:21.050
And I'm going to name it to something like explosion explosion.

18:21.450 --> 18:23.890
And we're going to make the animation fast way.

18:23.890 --> 18:27.610
So let's select all of these individual sprite by holding down shift.

18:27.610 --> 18:33.530
And let's move it or drag it on top of this explosion GameObject in the hierarchy in order to make the

18:33.570 --> 18:34.650
animation right away.

18:34.850 --> 18:43.050
Let's go to Assets Animation and I'm going to create a another folder for all of these things like uh,

18:43.090 --> 18:45.770
explosion animation or coin animation.

18:45.770 --> 18:49.690
So I'm going to create another folder for that, another subfolder.

18:49.690 --> 18:52.530
So I'm going to right click new Folder.

18:52.530 --> 19:01.410
And I'm going to call this folder to something like uh explosion uh or staff animation, something like

19:01.410 --> 19:01.650
that.

19:01.650 --> 19:05.250
We can call and let's open up this folder as well.

19:05.250 --> 19:06.850
And we have to name the animation.

19:06.850 --> 19:09.370
So I'm going to call it explosion.

19:10.210 --> 19:11.770
And let's click on save.

19:11.810 --> 19:13.690
And let's go to animation tab.

19:13.690 --> 19:15.050
Click on this play button.

19:15.050 --> 19:21.410
Now we are able to see but it's uh it seems like this is pretty much big the explosion.

19:21.410 --> 19:24.370
So I'm gonna make it a little bit small these sprites.

19:24.370 --> 19:27.330
So I'm going to move over to my project tab sprite sheet.

19:27.330 --> 19:30.770
And I'm going to make this pixel per unit to something like 20.

19:31.130 --> 19:33.730
And let's click on this apply button in the bottom.

19:33.850 --> 19:35.770
Still, it seems a little bit bigger.

19:35.770 --> 19:38.850
So I'm going to make something around 24.

19:39.050 --> 19:42.090
And let's click on this apply button by scrolling down.

19:42.290 --> 19:46.210
And now this uh, 24 seems pretty much good.

19:46.410 --> 19:49.890
Uh, and we also don't want this animation clip to be looped.

19:49.890 --> 19:53.170
So we're gonna, we're gonna uncheck the loop time.

19:53.450 --> 19:57.130
So in order to do let's move over to project tab assets.

19:57.130 --> 20:04.450
And then animation stops animation basically go over to that folder where you just place it your animation.

20:04.450 --> 20:11.050
So in my case this stop animation sub folder and I can see the explosion animation clip over here.

20:11.250 --> 20:16.570
And what we need to do, we're gonna uh, we don't want this animation clip to be loop.

20:16.570 --> 20:20.530
So that's why firstly I'm going to select my, uh, that animation clip.

20:20.530 --> 20:26.770
Let's move over to Inspector and I'm going to uncheck the loop time in order to uh, basically I don't

20:26.770 --> 20:28.690
want animation clip to loop.

20:28.930 --> 20:32.260
And we're going to make this explosion a game object as well.

20:32.300 --> 20:38.740
A prefab, because we're gonna spawn this explosion once this enemy game object dies, as well as this

20:38.740 --> 20:39.860
player game object.

20:39.860 --> 20:46.740
So we're gonna spawn at that time, and we don't want this explosion game object to be the default in

20:46.740 --> 20:49.220
our scene view as well as in the hierarchy.

20:49.220 --> 20:51.700
So let's firstly make it this one prefab.

20:51.700 --> 20:54.820
So we're going to select our explosion GameObject in the hierarchy.

20:54.940 --> 20:57.500
And let's drag it over to this prefab folder.

20:58.540 --> 21:00.940
And we're going to remove it from now.

21:02.740 --> 21:06.220
And we're gonna spawn once this enemy game object dies.

21:06.220 --> 21:10.820
So let's open up our enemy script quickly by double clicking on it.

21:11.020 --> 21:13.100
And let's go to the top of our class.

21:13.100 --> 21:15.980
But before we do, let's go where we're dying.

21:15.980 --> 21:18.060
So over here, as you can see.

21:18.060 --> 21:21.900
So before we type, we just want to show that explosion game object.

21:21.900 --> 21:28.140
So that's why we're gonna before we do, before we destroy our enemy game object, we're going to spawn

21:28.140 --> 21:31.540
that explosion game object or that effect.

21:31.540 --> 21:38.220
And in order to spawn that we do know, we need to use this instantiate function and this instantiate

21:38.220 --> 21:39.740
function as a first argument.

21:39.740 --> 21:42.580
It's going to take the game object you want to show up.

21:42.580 --> 21:44.180
So in our explosion.

21:44.180 --> 21:48.620
And the second thing it's going to take the position where you just want to show up.

21:48.620 --> 21:51.180
And the third thing it's going to take the rotation.

21:51.180 --> 21:56.500
So let's go to the top of our class and let's declare those variable by one by one.

21:56.500 --> 21:58.260
So let's go to top of our class.

21:58.260 --> 22:00.700
And I'm going to make it somewhere over here.

22:00.700 --> 22:02.380
So let's make a public.

22:02.380 --> 22:06.060
And that explosion game object itself a whole game object.

22:06.060 --> 22:08.420
So that's why we need to type this game object.

22:08.420 --> 22:11.340
And we can call this one to something like explosion.

22:11.340 --> 22:13.580
So I'm going to call it explosion.

22:13.580 --> 22:15.580
And let's close that up with semicolon.

22:15.580 --> 22:21.540
And make sure once you move over to unity and drag the reference or else you're going to get some error

22:21.580 --> 22:22.100
error.

22:22.100 --> 22:24.900
So I'm going to move over to my instantiate function.

22:24.900 --> 22:30.780
So as a first argument it's going to take the game object or the effect that you want to show.

22:30.780 --> 22:32.860
So in my case, this explosion.

22:32.860 --> 22:35.060
And the second thing it's going to take the position.

22:35.060 --> 22:40.940
So I'm going to pass this transform dot position basically means center position of our enemy game object

22:40.980 --> 22:44.140
or the current position of our enemy game object.

22:44.140 --> 22:46.340
And the third thing it's going to take the rotation.

22:46.340 --> 22:49.180
So we don't we're not gonna rotate like that.

22:49.180 --> 22:54.460
So we're going to simply pass quaternion dot identity basically means no rotation.

22:54.460 --> 22:56.460
And let's close that up with semicolon.

22:56.460 --> 22:58.260
And then we're going to press down Ctrl s.

22:58.300 --> 22:59.860
And let's move to unity.

22:59.860 --> 23:04.300
So underneath our enemy script we're able to see that field says explosion.

23:04.300 --> 23:09.420
So what we need to do right there we need to drag the explosion game object into that slot.

23:09.420 --> 23:12.500
So we're going to have the game object or the explosion effect.

23:12.500 --> 23:14.780
Then we can spawn that.

23:14.980 --> 23:17.420
So now let's have a look on this.

23:17.420 --> 23:23.380
So as soon as our enemy script gets compiled we can see underneath our enemy script explosion.

23:23.380 --> 23:26.220
And it says none game object basically empty.

23:26.220 --> 23:30.460
So what we need to do, we need to drag the explosion game object over here.

23:30.460 --> 23:32.020
So we're going to have the reference.

23:32.020 --> 23:38.940
So let's go to assets and then prefabs folder basically where we drag it and I have it over here.

23:38.940 --> 23:42.500
So I'm going to select that and let's drag it over to this slot.

23:42.700 --> 23:47.860
And we can see by now we have the explosion game object as you can see.

23:47.860 --> 23:52.020
So we can just click on this play button in the top in order to play our game.

23:52.020 --> 23:53.980
And let's have a look on this.

24:00.580 --> 24:02.180
So just wait for it to compile.

24:02.660 --> 24:07.700
And if we just, uh, attack on this enemy game object three times, you will see that.

24:09.220 --> 24:16.020
So as you can see, as soon as our enemy game object dies, the explosion game object just shows up.

24:16.020 --> 24:20.420
So if we move over to hierarchy, we still have the explosion game object.

24:20.420 --> 24:22.060
As you can see the.

24:22.060 --> 24:27.630
So we also need to destroy this explosion came object after some period of time.

24:27.830 --> 24:34.030
And also we can see that the position of that explosion game object is a kind of bit weird.

24:34.030 --> 24:36.230
So we need to move it a little bit down.

24:36.230 --> 24:40.070
So let's get out of play mode and let's create an empty game object.

24:40.070 --> 24:43.430
And we're gonna move that in the bottom of this player game object.

24:43.430 --> 24:50.150
Because from that point or that game object or that position, we just want to show up the explosion

24:50.150 --> 24:52.750
game object or that explosion effect.

24:52.990 --> 24:57.870
So let's create an empty game object or in this anime game object.

24:57.870 --> 25:00.550
So I'm going to right click on this anime one game object.

25:00.550 --> 25:03.070
And let's create an empty game object.

25:03.070 --> 25:06.830
And I'm going to call this game object to something like Explosion Point.

25:07.070 --> 25:12.630
So let's call it explosion point or explosion position.

25:12.790 --> 25:14.630
And I'm going to drag it in the bottom.

25:14.630 --> 25:16.510
So let's select this move tool.

25:16.630 --> 25:21.750
And I'm going to move it somewhere a fit of this player game object somewhere around here.

25:22.150 --> 25:24.870
And I'm gonna choose an icon or gizmos.

25:24.910 --> 25:26.230
And this seems fine.

25:26.430 --> 25:28.590
And let's open up our anime script.

25:29.150 --> 25:31.430
So let's open that up quickly.

25:32.030 --> 25:38.630
So what I want to do, I want to replace this transform dot position with our explosion point as we

25:38.630 --> 25:39.230
created.

25:39.230 --> 25:43.710
But before we remove, we need a reference of that point that we created.

25:43.710 --> 25:47.350
So let's go to top of our class and let's grab the reference first.

25:47.350 --> 25:49.070
So we're going to make a public.

25:49.350 --> 25:51.030
And that is a transform.

25:51.030 --> 25:53.590
Basically we're just looking for position.

25:53.590 --> 25:55.630
So that's why we're going to type transform.

25:55.630 --> 25:58.950
And we can call this one to something like explosion point.

25:58.950 --> 26:02.150
So I'm going to call it explosion point or position.

26:03.230 --> 26:05.150
And let's close that up with semicolon.

26:05.150 --> 26:07.790
And let's go to that line of code over here.

26:07.790 --> 26:11.030
And I'm going to replace this with explosion point.

26:11.270 --> 26:17.510
And make sure you just drag the reference in the inspector once you move over to unity.

26:17.910 --> 26:21.910
And now what we have to do, we just created this explosion.

26:22.070 --> 26:27.590
Basically, we spawned this explosion in this position with no rotation, as you can see.

26:27.750 --> 26:32.110
So after spawning, we're gonna store this into another variable.

26:32.110 --> 26:34.110
So this itself a whole game object.

26:34.110 --> 26:38.270
So what we're going to do, we're going to store into a another game object variable.

26:38.270 --> 26:43.270
And we can call this one to something like tame explosion steam explosion.

26:43.270 --> 26:45.230
And let's set equal to this.

26:45.230 --> 26:51.790
So firstly what we have done we just spawned this explosion in this point or this position with no rotation.

26:51.790 --> 26:58.350
And after that we just we just take in that explosion, uh, basically spawn that explosion effect and

26:58.390 --> 27:00.990
we whatever we spawn it, we just taking that.

27:00.990 --> 27:04.830
So in our case it's just going to be explosion effect that we know.

27:04.830 --> 27:08.910
So uh, after spawning it, we're just taking this explosion effect.

27:08.910 --> 27:14.430
And then we're storing into this explosion a game object as you can see.

27:14.430 --> 27:16.750
So it's gonna work like as a container.

27:16.750 --> 27:20.550
So firstly we spawn it and then we just uh, responded.

27:20.550 --> 27:21.070
Whatever.

27:21.070 --> 27:27.430
We responded, we just, uh, we just take in that and then we store it into this explosion container,

27:27.470 --> 27:33.990
as you can see, or this steam explosion game object or Tim basically referencing the temporary.

27:34.190 --> 27:37.750
So firstly, we spawn it at this position with no rotation.

27:37.750 --> 27:42.390
And after that, whatever we spawn it, we just store it in this steam explosion.

27:42.390 --> 27:44.550
So we spawn that explosion effect.

27:44.550 --> 27:51.270
So, uh, after spawning we just taking that explosion effect and then we storing into this steam explosion

27:51.270 --> 27:54.470
container or this steam explosion game object.

27:54.470 --> 28:00.670
And after that, what we have to do, we also need to delete that explosion container basically where

28:00.670 --> 28:03.310
we stored that explosion effect.

28:03.310 --> 28:07.950
So we also need to destroy the explosion effect after some period of time.

28:07.950 --> 28:10.990
So we're going to use this destroy function in order to destroy.

28:11.030 --> 28:14.870
So as a first argument we do know it's going to take the game object.

28:14.870 --> 28:17.310
So you want to try you want to destroy.

28:17.310 --> 28:19.360
So in our case stem explosion.

28:19.600 --> 28:24.640
And we don't know, we just started that explosion effect into this stem explosion.

28:24.640 --> 28:28.200
Or you can say you can say like in this container.

28:28.200 --> 28:35.000
So we just also destroying that container basically where we store it that time explosion or that explosion

28:35.000 --> 28:35.520
effect.

28:35.520 --> 28:43.200
So we also destroying as well as you can see, but we can specify this as a second argument that time

28:43.200 --> 28:47.000
because we just want to complete the explosion effect animation.

28:47.000 --> 28:49.240
And after that we just want to destroy.

28:49.240 --> 28:52.400
So that's why as a comma we're gonna specify the time.

28:52.560 --> 28:57.680
But before we specify the time, make sure you just go to unity and see the time limit.

28:57.720 --> 29:03.760
Basically we can move over to project tab, then assets and then prefabs folder basically where we drag

29:03.760 --> 29:06.160
the explosion and we can see it over here.

29:06.160 --> 29:11.840
So we can simply double click or double click on it in order to open that up in prefab mode.

29:11.840 --> 29:16.520
And if we move over to animation and we can see the animation over here.

29:16.560 --> 29:18.600
So something like 0.9 second.

29:18.640 --> 29:24.840
As you can see, it's just completing the whole animation clip, as you can see in this scene view as

29:24.840 --> 29:25.240
well.

29:25.400 --> 29:30.080
So after this amount of time we also need to destroy this explosion effect.

29:30.080 --> 29:37.040
So we do know we just firstly spawn it and we just store this explosion game object or that effect into

29:37.040 --> 29:38.400
this explosion.

29:38.400 --> 29:43.000
And after that we also destroying the explosion basically where we store it.

29:43.000 --> 29:45.920
So as a second argument we're gonna specify the time.

29:45.920 --> 29:48.040
So we're gonna pass 0.98.

29:48.160 --> 29:54.520
And we do know after this amount of time which is 0.9 F, it just completely, then completing the whole

29:54.520 --> 30:00.360
animation clip and after completing the whole animation clip, uh, we just want to destroy.

30:00.360 --> 30:06.960
So that's why as a second argument, we just specify the time, which is 0.9 F, because after after

30:06.960 --> 30:10.720
this amount of time, it's just completing the whole animation clip.

30:10.720 --> 30:12.120
So that is the reason.

30:12.120 --> 30:18.120
And we're gonna close that up with semicolon in order to, uh, just, uh, save our code.

30:18.120 --> 30:19.480
So I'm going to press down Ctrl.

30:19.520 --> 30:25.120
S to save our code and make sure you just close that off with semicolon as well.

30:25.120 --> 30:29.040
So now let's move over to unity and have a look on this.

30:31.680 --> 30:33.840
So just wait for a little moment.

30:39.840 --> 30:41.000
So we need to go back.

30:41.000 --> 30:43.120
So in hierarchy we can see back arrow.

30:43.120 --> 30:46.120
So just click there in order to move in scene view.

30:46.840 --> 30:48.840
And uh let's have a look.

30:48.840 --> 30:54.960
But before we do make sure you select your anime game or anime one game object or the anime and select

30:54.960 --> 30:57.920
this explosion point and drag it right there.

30:57.920 --> 31:01.680
Because from this position we want to spawn that explosion effect.

31:01.680 --> 31:03.920
So we need to drag the reference right there.

31:03.920 --> 31:09.800
So we're going to have the position and then we can spawn it or else you're gonna get some weird errors.

31:09.800 --> 31:16.960
So make sure you just drag the explosion point uh game object or this position in corresponding slot.

31:17.160 --> 31:18.840
And now let's have a look on this.

31:18.840 --> 31:25.160
So I'm going to click on this play button in the top to play our game to uh, basically uh to play our

31:25.160 --> 31:25.520
game.

31:25.720 --> 31:29.280
And I really apologize for the background noises coming out.

31:30.400 --> 31:32.080
So let's have a look on this.

31:32.080 --> 31:36.880
So I'm gonna click shoot on this anime game object three times 123.

31:37.040 --> 31:44.560
As you can see, as soon as we have done that explosion game object, we are not able to see explosion

31:44.560 --> 31:49.920
called a clone in the hierarchy as well as that game object just get destroyed.

31:49.920 --> 31:54.680
So we also destroyed that enemy as well as the explosion effect we have shown.

31:54.680 --> 31:57.000
We also just destroying that.

31:57.000 --> 32:01.000
So let's get out of play mode and we need to adjust the explosion point.

32:01.440 --> 32:05.160
Basically we need to drag it a little bit up somewhere over here.

32:05.160 --> 32:11.440
So the explosion effect is going to be a perfect, uh, position in order to show up perfectly.

32:11.440 --> 32:16.770
So I'm going to select my explosion point game object, and I'm going to drag it somewhere around here

32:16.770 --> 32:21.770
I guess uh, I guess this this is gonna be perfect point.

32:21.770 --> 32:25.090
So let's have a look and make sure you just go to overrides.

32:25.330 --> 32:28.210
Uh, so basically select the parent game object first.

32:28.210 --> 32:33.290
So in our case this enemy one let's go to overrides and then click on Apply All.

32:33.610 --> 32:38.610
And now let's click on this play button at the top in order to see one more time.

32:40.250 --> 32:42.370
So just wait for it to compile.

32:42.370 --> 32:44.650
And once it's done we are ready to go.

32:45.050 --> 32:49.170
And you can just play around with that and you're gonna get the hang of it.

32:49.690 --> 32:57.890
So let's as you can see now, it's a perfectly working and it's a it's a cool thing.

32:57.890 --> 32:59.330
I hope you get the idea.

32:59.330 --> 33:01.770
So I'm gonna get out of my play mode.

33:02.410 --> 33:02.890
Play mode?

33:02.890 --> 33:04.330
I'm gonna get out of play mode.

33:04.330 --> 33:04.810
Sorry.

33:04.930 --> 33:06.610
I really apologize for that.

33:07.250 --> 33:10.730
So let's have a look in the next lecture as well.

33:10.770 --> 33:11.690
Next lecture.
