Hello guys.
Welcome to the video.
In this one I want to show you how to kill the player so we can respond him in the next video.
So killing the player will be very easy.
Uh, let's go to the player script and maybe below the knockback.
I want to make a method public void die, which will do one simple thing.
It will do destroy game object.
So we're going to destroy the player.
Let's save this and let's go back to unity.
And since we don't want to kill player just like that, let's make a place where he could fall into
the pit.
And because of that, he would be killed.
I'm going to just go ahead to Tile Palette.
And over here I want to erase a little bit.
Maybe like that.
Yeah.
So now we have a place to fall, and we need some sort of an object with a trigger area that would kill
the player.
So let's make a C sharp script.
And I'm going to call it Dead Zone.
And this dead zone.
We only need one thing.
We're going to type here on trigger, enter 2D and it's going to be very similar to Damage Trigger.
So I'm going to go ahead and copy this code from here.
But instead of doing a knockback I will just call method die.
Just like that.
Let's save this.
Now, back in unity, we want to make a 2D image so we can see where is a dead zone.
Later on we're going to switch off the image so player cannot see them.
But we need to see that.
So we know how to you know develop the game.
So let's do 2D sprite square.
Let's name it as dead zone.
For the sorting layer.
I think we can choose background and we want to place it in front of a background.
So let's do order in layer one.
Now it will be always in front of a background.
We can stretch the image to something like that.
Let's move it down.
Okay, let's make it red.
Maybe be transparent.
Just like so.
And now we just need to put a box collider on it.
I'm going to do a box Collider 2D.
You're going to make it is trigger.
And then we're going to put the script on the game object.
So now this will work when somebody enters the trigger and if I'm not mistaken, player will walk into
the area and he'll just be destroyed.
Okay, perfect.
We also need to respawn the player, but we're going to do that in the next video.
As of now, let's just make a visual effect for the death of the player and we're going to move on.
So one of the ways to do visual effect would be to make an animation over here, because we have animation
in the graphics main character over here we have disappearing sort of animation and we could place it
here, then make trigger and transfer to that animation and maybe freeze the movement of the player
or something like that.
But actually I think there is a better way.
Let's select these two objects and we need to be sure we have pixel per unit 16.
I'm going to hit apply.
And I'm going to take this effect over here this sprite and drag it into the scene.
Let me put it on a player layer with an order minus one.
Now I'm going to name it as player.
Death wave fix.
And I'm going to make animator controller for this one.
We're going to go to animations over here.
I think we can make a folder for fruits.
Let's take them.
Put them here.
Oh.
I'm sorry.
It should be.
Routes.
Okay, on the player, I think we can make an animation and I mean animator controller.
Player.
Death by fix.
All right, let's put it on this visual effect, just like so.
And now we need to create a clip.
Let's do create.
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.
I'm going to make a visual effect.
I'm going to instantiate the visual effect.
And that's it.
Now let's go to player and do.
Player death prefix.
Maybe just like that.
And we need to go to graphics now.
Main character.
Find these disappearing sprites.
Put them here.
Drag them here.
Then let's make sample rate 20.
And let's go to the script.
And over here we have this fruit pick up.
We fix.
Which actually just doing the destroy me function.
So maybe we can open the script, select the name, press Ctrl R, make sure you check this rename symbols
file.
This is important.
And then let's just give it a name.
Destroy me event just that.
So now we have the script and we can place it on any object that should be destroyed.
Um.
I'm just going to quickly go and check if fruit visual effect is fine if I did not break anything.
And set prefab.
Route.
Visual effect.
Animation.
It's okay.
Good.
Now let's go back to this visual effect.
And over here in the end, after the last frame I'm going to add event.
Oh, sorry.
We need to put the script on.
Let's do destroy Me event.
So we added new component.
And now.
We can go to events over here and choose Destroy Me event.
Very nice.
Now we can go to prefabs and I think we can make folder for these objects.
So I'm going to do folder.
Roots.
Just drag them here.
Actually, maybe everything except the visual effect.
And then let's drag player this way.
Fix over here so we can use it.
I think on a player we can open the script and somewhere at the bottom I'm going to do header.
They fix serialize field private GameObject death may fix.
Maybe there is a better place for this one, but as of now, this is just fine because we have only
one visual effect.
Then let's go to method where we die and we're going to open curly brackets.
And over here I'm going to do GameObject.
New death wave fix equals to instantiate this wave fix transform position.
Then we're not going to change rotation.
So it's going to be quaternion identity.
And I think this is all what we need to have because effect will destroy itself.
Okay.
Now let's go back and we're going to remove this object over here.
And we're going to jump into this death area and see if visual effect is there.
It is not there.
Okay.
My bad.
I know what is the problem.
We destroyed the object.
So this line of code did not work.
We actually need to make a visual effect.
Then we need to destroy the player.
Okay?
Let me see.
Oh, no.
It was not assigned.
I forgot to assign it.
Let's go to prefab.
On the player.
We need to drag this one just like so, and now we can clean it and go to play mode.
And finally.
You okay.
Very cool.
Now we're going to go to the next video and there we're going to make a respawn system.
I'll see you there.