WEBVTT

00:00.020 --> 00:00.560
Hello guys.

00:00.560 --> 00:01.700
Welcome to the video.

00:01.700 --> 00:07.220
In this one I want to show you how to kill the player so we can respond him in the next video.

00:07.220 --> 00:09.800
So killing the player will be very easy.

00:10.400 --> 00:13.640
Uh, let's go to the player script and maybe below the knockback.

00:13.640 --> 00:19.610
I want to make a method public void die, which will do one simple thing.

00:19.610 --> 00:23.000
It will do destroy game object.

00:23.000 --> 00:24.650
So we're going to destroy the player.

00:24.650 --> 00:28.010
Let's save this and let's go back to unity.

00:28.010 --> 00:33.350
And since we don't want to kill player just like that, let's make a place where he could fall into

00:33.350 --> 00:33.860
the pit.

00:33.860 --> 00:35.720
And because of that, he would be killed.

00:36.350 --> 00:39.920
I'm going to just go ahead to Tile Palette.

00:40.190 --> 00:43.820
And over here I want to erase a little bit.

00:44.920 --> 00:46.330
Maybe like that.

00:48.010 --> 00:48.460
Yeah.

00:48.460 --> 00:54.130
So now we have a place to fall, and we need some sort of an object with a trigger area that would kill

00:54.130 --> 00:54.910
the player.

00:54.910 --> 00:57.280
So let's make a C sharp script.

00:58.410 --> 01:00.300
And I'm going to call it Dead Zone.

01:01.480 --> 01:02.470
And this dead zone.

01:02.470 --> 01:04.210
We only need one thing.

01:04.210 --> 01:09.610
We're going to type here on trigger, enter 2D and it's going to be very similar to Damage Trigger.

01:09.610 --> 01:13.810
So I'm going to go ahead and copy this code from here.

01:13.810 --> 01:19.870
But instead of doing a knockback I will just call method die.

01:20.710 --> 01:21.490
Just like that.

01:21.490 --> 01:23.350
Let's save this.

01:23.890 --> 01:28.600
Now, back in unity, we want to make a 2D image so we can see where is a dead zone.

01:28.600 --> 01:31.660
Later on we're going to switch off the image so player cannot see them.

01:31.660 --> 01:32.950
But we need to see that.

01:32.950 --> 01:35.560
So we know how to you know develop the game.

01:35.560 --> 01:38.740
So let's do 2D sprite square.

01:38.740 --> 01:40.630
Let's name it as dead zone.

01:41.530 --> 01:42.610
For the sorting layer.

01:42.610 --> 01:47.110
I think we can choose background and we want to place it in front of a background.

01:47.110 --> 01:49.900
So let's do order in layer one.

01:49.900 --> 01:53.110
Now it will be always in front of a background.

01:53.470 --> 01:56.770
We can stretch the image to something like that.

01:56.770 --> 01:58.570
Let's move it down.

01:59.810 --> 02:01.880
Okay, let's make it red.

02:02.570 --> 02:03.980
Maybe be transparent.

02:03.980 --> 02:05.150
Just like so.

02:05.810 --> 02:09.020
And now we just need to put a box collider on it.

02:09.020 --> 02:11.240
I'm going to do a box Collider 2D.

02:12.160 --> 02:14.410
You're going to make it is trigger.

02:14.410 --> 02:17.140
And then we're going to put the script on the game object.

02:18.210 --> 02:25.200
So now this will work when somebody enters the trigger and if I'm not mistaken, player will walk into

02:25.200 --> 02:28.350
the area and he'll just be destroyed.

02:28.380 --> 02:30.180
Okay, perfect.

02:30.210 --> 02:34.320
We also need to respawn the player, but we're going to do that in the next video.

02:34.320 --> 02:38.790
As of now, let's just make a visual effect for the death of the player and we're going to move on.

02:38.790 --> 02:45.450
So one of the ways to do visual effect would be to make an animation over here, because we have animation

02:45.450 --> 02:51.360
in the graphics main character over here we have disappearing sort of animation and we could place it

02:51.360 --> 02:57.210
here, then make trigger and transfer to that animation and maybe freeze the movement of the player

02:57.210 --> 02:58.230
or something like that.

02:58.230 --> 03:00.240
But actually I think there is a better way.

03:01.440 --> 03:06.780
Let's select these two objects and we need to be sure we have pixel per unit 16.

03:07.110 --> 03:08.190
I'm going to hit apply.

03:08.190 --> 03:13.170
And I'm going to take this effect over here this sprite and drag it into the scene.

03:14.180 --> 03:18.920
Let me put it on a player layer with an order minus one.

03:20.520 --> 03:23.370
Now I'm going to name it as player.

03:24.090 --> 03:26.070
Death wave fix.

03:26.070 --> 03:29.190
And I'm going to make animator controller for this one.

03:29.280 --> 03:31.530
We're going to go to animations over here.

03:31.530 --> 03:34.140
I think we can make a folder for fruits.

03:36.010 --> 03:36.970
Let's take them.

03:36.970 --> 03:38.110
Put them here.

03:39.010 --> 03:39.220
Oh.

03:39.220 --> 03:39.670
I'm sorry.

03:39.670 --> 03:40.420
It should be.

03:41.930 --> 03:42.560
Routes.

03:42.560 --> 03:49.850
Okay, on the player, I think we can make an animation and I mean animator controller.

03:51.020 --> 03:51.920
Player.

03:51.920 --> 03:53.510
Death by fix.

03:53.540 --> 03:57.230
All right, let's put it on this visual effect, just like so.

03:57.230 --> 03:59.420
And now we need to create a clip.

03:59.420 --> 04:00.800
Let's do create.

04:00.890 --> 04:05.900
If you didn't get what I'm trying to do, I'm going to do the same thing as I did for the fruit.

04:05.900 --> 04:07.250
I'm going to make a visual effect.

04:07.250 --> 04:08.900
I'm going to instantiate the visual effect.

04:08.900 --> 04:09.710
And that's it.

04:10.400 --> 04:12.650
Now let's go to player and do.

04:13.510 --> 04:15.730
Player death prefix.

04:15.730 --> 04:16.870
Maybe just like that.

04:17.650 --> 04:19.900
And we need to go to graphics now.

04:20.580 --> 04:22.020
Main character.

04:22.020 --> 04:23.580
Find these disappearing sprites.

04:23.580 --> 04:24.540
Put them here.

04:24.540 --> 04:25.650
Drag them here.

04:25.650 --> 04:28.080
Then let's make sample rate 20.

04:29.050 --> 04:32.290
And let's go to the script.

04:32.740 --> 04:34.930
And over here we have this fruit pick up.

04:34.930 --> 04:35.740
We fix.

04:37.540 --> 04:40.810
Which actually just doing the destroy me function.

04:40.810 --> 04:48.670
So maybe we can open the script, select the name, press Ctrl R, make sure you check this rename symbols

04:48.670 --> 04:49.420
file.

04:49.900 --> 04:51.010
This is important.

04:51.010 --> 04:53.050
And then let's just give it a name.

04:54.150 --> 04:57.510
Destroy me event just that.

04:57.510 --> 05:02.100
So now we have the script and we can place it on any object that should be destroyed.

05:03.140 --> 05:03.560
Um.

05:05.340 --> 05:10.410
I'm just going to quickly go and check if fruit visual effect is fine if I did not break anything.

05:11.300 --> 05:12.830
And set prefab.

05:13.620 --> 05:13.860
Route.

05:13.860 --> 05:14.910
Visual effect.

05:15.690 --> 05:16.890
Animation.

05:19.560 --> 05:20.310
It's okay.

05:20.310 --> 05:20.820
Good.

05:20.820 --> 05:22.920
Now let's go back to this visual effect.

05:22.920 --> 05:27.690
And over here in the end, after the last frame I'm going to add event.

05:28.770 --> 05:29.310
Oh, sorry.

05:29.310 --> 05:30.840
We need to put the script on.

05:30.990 --> 05:33.480
Let's do destroy Me event.

05:33.480 --> 05:35.460
So we added new component.

05:35.640 --> 05:36.720
And now.

05:37.660 --> 05:42.460
We can go to events over here and choose Destroy Me event.

05:42.460 --> 05:43.510
Very nice.

05:43.510 --> 05:47.350
Now we can go to prefabs and I think we can make folder for these objects.

05:47.350 --> 05:48.940
So I'm going to do folder.

05:49.930 --> 05:50.530
Roots.

05:50.530 --> 05:52.660
Just drag them here.

05:52.690 --> 05:55.630
Actually, maybe everything except the visual effect.

05:55.900 --> 05:58.480
And then let's drag player this way.

05:58.480 --> 06:00.520
Fix over here so we can use it.

06:02.420 --> 06:08.900
I think on a player we can open the script and somewhere at the bottom I'm going to do header.

06:09.820 --> 06:15.880
They fix serialize field private GameObject death may fix.

06:15.880 --> 06:20.440
Maybe there is a better place for this one, but as of now, this is just fine because we have only

06:20.440 --> 06:21.490
one visual effect.

06:21.490 --> 06:26.500
Then let's go to method where we die and we're going to open curly brackets.

06:27.450 --> 06:30.570
And over here I'm going to do GameObject.

06:30.840 --> 06:38.520
New death wave fix equals to instantiate this wave fix transform position.

06:38.520 --> 06:40.440
Then we're not going to change rotation.

06:40.440 --> 06:42.900
So it's going to be quaternion identity.

06:43.350 --> 06:49.140
And I think this is all what we need to have because effect will destroy itself.

06:50.040 --> 06:50.670
Okay.

06:50.820 --> 06:55.860
Now let's go back and we're going to remove this object over here.

06:56.790 --> 07:02.610
And we're going to jump into this death area and see if visual effect is there.

07:03.400 --> 07:04.690
It is not there.

07:04.720 --> 07:05.650
Okay.

07:05.650 --> 07:06.490
My bad.

07:06.520 --> 07:07.960
I know what is the problem.

07:07.960 --> 07:09.220
We destroyed the object.

07:09.220 --> 07:11.080
So this line of code did not work.

07:11.080 --> 07:13.180
We actually need to make a visual effect.

07:13.180 --> 07:15.130
Then we need to destroy the player.

07:15.610 --> 07:16.270
Okay?

07:19.340 --> 07:20.180
Let me see.

07:22.450 --> 07:23.230
Oh, no.

07:25.090 --> 07:26.350
It was not assigned.

07:26.380 --> 07:27.610
I forgot to assign it.

07:27.610 --> 07:29.080
Let's go to prefab.

07:30.050 --> 07:30.920
On the player.

07:30.920 --> 07:36.590
We need to drag this one just like so, and now we can clean it and go to play mode.

07:37.540 --> 07:38.770
And finally.

07:40.190 --> 07:41.630
You okay.

07:41.630 --> 07:42.560
Very cool.

07:42.560 --> 07:48.020
Now we're going to go to the next video and there we're going to make a respawn system.

07:48.020 --> 07:49.160
I'll see you there.
