Hello guys.
Welcome to the video.
In this one I want to show you how to make a fire trap.
It's going to be a super simple one.
There is a button.
You step on a button to switch off the fire, then you run, then fire switches on back again.
This is how it's going to be.
First, what I want to do is to maybe take some things away from the level because they distracted me.
So I'm going to delete arrow.
I want to switch on the trampoline.
I kind of like it.
So I'm going to place it over here.
And then following platform I'm going to remove it remove it remove it.
Spike ball remove it okay.
Now let's develop the trap fire.
First we want to make GameObject.
And also we want to set up controllers.
Let's go to Graphics Traps fire.
I'm going to select all of them.
Make pixel per unit 16.
Then we're going to take the fire itself, drag it to the scene.
Let's name it as, uh, trap fire.
Is going to be traps sorting layer.
Let's give it a capsule collider.
This time capsule Collider 2D because I think the shape is fitting the shape of the trap very well.
So this is how it should be.
And let's make it is trigger because this one going to damage the player.
Yeah.
Now we need an animator for this one.
Let's go to animations, traps, controllers.
Let's make animator controller trap fire.
And also, while we are here, let's make animator for the button trap fire.
Button.
Okay.
We're going to put.
Trap fire on this one.
And then we're going to make an animation.
Let's go to assets animation traps.
We're going to do trap fire active.
When I go to graphics traps fire.
Let's take on drag them here.
Sample rate 20.
Now there is a fire.
We also need an off animation.
So I'm going to do trap fire idle.
I'm just going to drag it here.
So now it's switched off.
Very cool.
Now we can go to animator itself and set up Boolean parameter bool.
Active.
Uh, we're going to transfer to idle if active is false.
No exit time.
Transition duration zero.
Then we're going to transfer back.
If active is true.
Now.
Exit time.
Transition duration zero.
Okay, job, fire is ready.
Now let's make a button.
Going to take one of the sprites.
I want to take this one.
Drag it here.
And let's make it as Trump.
Fire button and I'm going to make it as a child of a trap.
Fire!
Okay.
We need animator controller, and I think we can just type here.
Trap, fire.
Uh, no, it's not there.
Okay, let's add animator.
Then we're going to open animator.
Click over here and find this trap fire button.
Okay cool.
Let's make certain layer as a traps.
Then on the animator we're going to make a couple of animations.
Let's do create asset animations traps trap fire button.
Uh idle.
It's going to be just this sprite.
And then one more trap fire button.
Activated.
And we're going to take all of the sprites, drag them here, make sample rate 20.
Nice.
Let's transfer to activate it with a trigger.
Activate.
So there's going to be condition for the transition.
Activate transition duration zero exit time uncheck.
Then we're going to go back over here and do.
Exit time one.
Transition duration zero.
Now I'm doing nothing different from what we did before all of this.
You know very well we did a bunch of traps, a bunch of setups.
This is basically the same, just combination of what we learned.
And I think I'm going to make this trap as a last one because it's time to move to another section.
Yeah.
Let's go to the scene.
Yeah.
On this button we need box collider so it can be triggered.
Box Collider 2D.
Let's set ease trigger over here.
And this is probably all for the initial setup.
This has a trigger collider okay.
And this is a trap fire okay.
Now let's go to scripts.
And I think we can make a folder for the trap scripts.
Trump's.
Going to take the traps and drag them to the folder.
Okay, now we're going to go inside and make two new scripts.
One of them going to be.
Trap.
Fire.
Another one going to be I is going to pop up now.
I hate it, I know it's fine.
Another one going to be trap fire button.
Okay.
This is what we have now.
We're going to select Trapwire button.
Give it a script.
And on the trapwire we're going to select I mean put Trapwire okay.
Now let's go inside of the scripts.
You're going to need trap and trap fire button on the trap itself.
We're going to make a method that would activate the fire or deactivate the fire according to the boolean
we pass in there.
So I'm going to do private void set fire bool active.
And now we need to change a bunch of parameters according to the boolean we have.
So one of them would be animation.
So private animator anim.
Also, there is a capsule collider because if we don't switch it off, we still can be damaged.
Let's do Collider.
We cannot do that.
Okay.
Wire Collider.
And we.
I think we just need a boolean private bool to know if wire is active is active.
Then in this method we're going to do this.
Um, we can just do enum set bool of active to active that we pass in through the parentheses.
We can also do fire collider enabled equals to active and is active equals to active.
Just like that.
Now let's.
Now make a coroutine that would switch off the fire.
Wait for the cooldown and switch it on.
Right, we need a cooldown itself, so I'm going to do serialize field private float.
Let's do off duration.
And then there's going to be enumerator.
Via coroutine.
Let's type here private.
So it's pretty.
Then we're going to do set fire.
Pulse, it's going to switch it off.
Then we're going to do.
Yield.
Return new.
Wait for a seconds of duration.
Then we're going to do set fire.
True.
So we're going to switch it on.
Also we want to switch on the fire at the start.
So I'm going to do start set fire.
True.
And also we want to get these components in the wake.
So I'm going to do a wake.
Einem Getcomponent via Collider.
Getcomponent of a capsule collider.
This is perfect.
Now what we need or I'm so sorry.
Now what we need is to.
Let me somehow move it closer so you can see everything together.
Yes, this will do.
Now we need to call this coroutine.
We need to start this coroutine from outside of this script.
We want to start this coroutine when player enters the button trigger.
And also, just in case, I want to be sure there is always a fire button.
So I want to make a reference to a.
The serialized field.
Private trap.
Fire button.
And then in the start over here, I'm going to check if fire button equals to null.
Then I'm going to do debug log warning.
You don't have fire button.
On.
Last game.
Objectname.
And basically that's just it.
Let's just do it like that.
So it's going to give us a message if we're missing a fire button.
And let's make a public method.
Public void switch off fire, which would do just startcoroutine.
Of a fire coroutine.
Nice.
This is ready.
So this one is pretty simple, I guess.
Much easier than things we did before.
Now let's go to trap fire button.
Over here.
We want to get a reference.
Private trap fire!
Trap fire.
And we need animator private animator anim.
Then in the wake, we can do anim and then trap fire equals to getcomponent in parent of a trap fire.
Nice.
Then we need on trigger.
Enter 2D.
And we're going to check player.
Player equals to collision game beam object player.
If player not equals to null then anim set trigger of activate.
So we activate the buttons animation and we take trap fire and ask it to switch off the fire.
All right that's all what we need.
I think I'm going to clean it up also, just in case when I show you script here.
Maybe let's squeeze it like so.
Oh is active is not used.
Yeah.
Actually, let's go to this method.
And type this.
Sorry.
Like.
So if is active, then return button cannot be activated if fire is active already.
Okay.
Well button will be activated, but we will not be able to start a coroutine.
Let's go back.
Over here.
We want to assign trap fire button.
Let's make duration maybe 2.5 seconds.
And the fire button itself.
I think we don't need anything else on the trap.
Fire.
I think we need the image trigger.
Okay.
Very cool.
Now, let's say you need a prefab of this.
You can just make it as a prefab.
And next time you need a trap fire, you just have to take the trap fire on the level, place it where
you want it to be.
For example, I want to place it over here, and then you take the button itself and move it somewhere,
and you just place the button over here.
Now we're going to go to the game mode.
Let's say I fell over here.
There is my fire trap.
Gonna go ahead.
Activate the button.
Oh, animation is activated, but fire is not switching off.
Oh, let me see why.
Probably.
I made a mistake.
Yeah, this one should be.
If is active false, then return.
Okay.
Let me try again.
Now there is some.
It's okay.
Doesn't matter.
Switched off the fire running and boom, fire is on.
There is a damage, so I have to switch it off before I go further.
Really nice, I like it.
Turn turn, turn.
Well, this could be a fun game, honestly.
Okay, that's it for this video and let's go to the next one.