Hello, guys.
In this video, we're going to make a trap, and it's going to be as easy as making a coin.
Let's create a 2D Sprite.
Asymmetric diamond.
I'm going to name it as Trump.
Let me find it.
Certainly there can be enemy and just minus one over here, and I'll try to rotate it like this.
Basically rotation just 90 on this Z.
I want to make it red color so it looks dangerous and add a collider box collider to DX.
Let's adjust the size just by a bit to something like this.
And now next step would be triggering action on entering the box.
Collider We need to check.
This box is Trigger, of course.
And now I'm going to add a script.
New script trap.
Just as a small task here, without my help, try to do on trigger enter and just debug a line like
player was knocked or something.
Go and do that.
I'll give you a couple of seconds to try and then I'm going to show you what we're going to do next.
One, two.
Okay.
So what we're going to do here is first set in and trigger enter.
And before we continue, let's go to player.
And below the update, I'm going to create a public function.
It should be public so I can get access to it.
Public void damage.
So damage for the player.
And what I want to do here is to check if speed is equals to maximum.
If speed.
What was that move?
Speed.
Equals to max speed.
Actually, let's use bigger or equals just in case.
Equals or bigger to max speed.
Then I'm going to do a knockback.
Else.
So if it's not bigger or equal to maximum speed, it is less.
Then I'm going to call just die.
So the idea here is to give a player a second chance when he has maximum speed, but if he doesn't have
anything, he should die.
If you played any games like Subway Surfer, you might remember that.
If I remember it correctly, you can run for some amount of time.
If you bump into something, you lose in speed.
If you bump again, you lose your game.
That's how it works and that's what we're doing here.
And actually with our set up that we have from before, very easy to set up, right?
Now let's go back to our trap.
And here I'm going to check for component of the player.
If collision dot get component of a player not equals to null, then we're going to do collision dot
get component of a player.
And we're going to call damage function.
Now I'm going to go back.
I'll make a prefab for this trap like this.
And then I'm going to go to level part.
Delete my coin generators from here.
Place a couple of traps.
One here.
Oh, it's really feasible here.
I don't like it.
Let's change something.
Let's open prefab of the trap like this.
Find spread, render and change certain layer from enemy to platform.
So it will be behind the platform by clicking this icon.
You going back?
Now let's go to level part again.
Now it is behind the platform.
I'm going to place it like this duplicate and place another one.
Somewhere here.
Now I'm going to test it.
And how it's supposed to work.
If I'll bump into Trump right now, I'll get death of the character.
Hey, it's not working.
Hmm.
Let's see.
Why is that?
Box collider is trigger.
Let's see the code.
What is going on?
I don't understand.
Let's debug line and see if we enter in the trigger at all.
Enter trigger.
So it's not about trigger, it's about function.
We created what's wrong with the function?
Public void if cells die.
Oh, I'm sorry.
Of course.
My bad.
Yeah.
We should start quoting here, not just type die.
So please forgive me for this.
So should be start quarantine.
I don't know.
How could I forget this and just do this?
Start quarantine.
So else, start quarantine.
Die.
Because this is a quarantine.
Let's go now.
And it's going to be fine.
Also, I changed the trigger collider just in case because of the collider.
But it's not, so I'll change it back.
Okay, So, boom, I died.
What if I try to jump over and get maximum speed?
Will I die?
Let's see.
I move.
Speed is 12.
Getting some speed now.
So it's 20 and just the knockback and death.
Cool.
I like it.
I'm sorry if we stumbled on a mistake there, but it's a development.
You cannot avoid it.
Even if you planned everything perfectly.
Sometimes you forget things and it's okay.
It's completely normal, I guess.
Honestly, when you develop in a game, nothing goes as smooth as a show.
When you hear you stumble.
It's so many things before you find the right way to make it work.
So if you have some trouble on making a game, please don't worry about it.
Just try.
Try until you find a solution and it will be fine.
So let's go to next video now.
See you.