Hello, guys.
In this video, we're going to make this of the player and I just want to make function now.
So later on, if we need we can just call it from the trap or from wherever we need.
So it's all set and ready to use, right?
First we need the boolean to kill the player and I don't want to create hell or just for that.
So for now I'll create public bool is dead just here.
Then I want to go to update.
And say if.
Is dead, then return.
And I want to make it true if I need.
So I'll copy this two lines of code, paste it in, and instead of K letter I will use.
Oh, and instead of this function, I'll make new one which I'll call just die.
Now I'll press alt enter and I can generate method.
Now we have this function here.
And what we can do is we can set.
Is that true?
We can knock back player a bit.
So it's going to be RB velocity equals to knock back direction and we can set boolean to true.
So anim set ball is that to true?
Right now let's go to Unity and set up animation going to select player animation, create new clip
player die.
Now we can go to graphics, find this knockback and take second Sprite up to fifth Sprite.
Drag it here and I want to make him hang in the air for a bit, so maybe I'll pull this two to the right.
So this sprite will be there for two frames.
Now let's change sample rate to 12.
So I guess now we can go to animator behind this animation player die, set it somewhere from the right
side and from any state we go into player die condition.
We didn't create it.
We need to do it.
Create.
Boolean is dead.
Let's drag it above.
Condition.
Is that true?
Transmission duration zero can transmit to self and check.
And we need to make sure if we go to this animation, we're not transferring to any other from any state
because this one still will be any state.
Right.
So let's go to this condition and add another one is that should be false.
Same for the knockback.
All right.
I guess we all set.
There is still something to do, but I want to do it step by step.
Now, if I press my old letter, I should die.
Boom.
Okay, so there is two issues we need to fix.
First one is animation.
It is looped.
So let's go to animations, find the player die, and then check loop time.
And second, you saw a player is still moving when I died.
So that is not okay.
I guess he should be pushed back just for a bit and then he should stop.
Check this out.
So what we do is we're going back to code and we can create code routine again instead of just function.
You remember how we did it in the knockback?
Yeah.
So instead of void, let's do a enumerator.
And then here we're going to do.
Yields.
Return new.
Wait 4 seconds.
I guess point five is okay.
And after that we're going to do RB dot velocity equals to new vector to zero zero.
Now we need to go above and type here, not die, but start core routine.
Start core routine.
They.
Okay, let's go back and see this.
And boom.
All right.
And now, oh, we still can die.
But we cannot jump.
We cannot move.
But we can die again and again.
I'm sure it won't be triggered in the game again and again.
But just in case, let's protect our self.
Let's go and make sure we can do this only if we press button and not is dead.
Okay.
And boom, if you think he's moving not long enough, we can just increase the volume and it will be
there.
Where is it?
Here.
We can put one second.
For example.
One.
Let me see if I can find any other bugs.
I'm going to press all the buttons we have.
Can I knock him?
Yes, I can.
I can do knock back.
You know how to fix that, right?
I'm going to give you a couple of seconds to try.
Do it yourself.
One, two.
Okay.
So once we die, we should set.
Can be knocked to false.
It can be knocked false.
Okay, We done here.
Let's go to next video.