WEBVTT

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

00:00.440 --> 00:01.430
Welcome to the video.

00:01.430 --> 00:04.370
In this one I want to show you how to make a fire trap.

00:04.370 --> 00:06.080
It's going to be a super simple one.

00:06.080 --> 00:07.250
There is a button.

00:07.250 --> 00:12.710
You step on a button to switch off the fire, then you run, then fire switches on back again.

00:12.710 --> 00:14.090
This is how it's going to be.

00:14.090 --> 00:19.130
First, what I want to do is to maybe take some things away from the level because they distracted me.

00:19.130 --> 00:20.390
So I'm going to delete arrow.

00:20.420 --> 00:22.190
I want to switch on the trampoline.

00:22.190 --> 00:23.420
I kind of like it.

00:23.720 --> 00:25.700
So I'm going to place it over here.

00:25.700 --> 00:31.010
And then following platform I'm going to remove it remove it remove it.

00:31.010 --> 00:33.140
Spike ball remove it okay.

00:33.140 --> 00:36.950
Now let's develop the trap fire.

00:37.010 --> 00:38.930
First we want to make GameObject.

00:38.930 --> 00:40.940
And also we want to set up controllers.

00:41.150 --> 00:44.510
Let's go to Graphics Traps fire.

00:44.510 --> 00:46.070
I'm going to select all of them.

00:46.070 --> 00:48.200
Make pixel per unit 16.

00:49.470 --> 00:53.610
Then we're going to take the fire itself, drag it to the scene.

00:53.970 --> 00:57.840
Let's name it as, uh, trap fire.

00:59.180 --> 01:02.480
Is going to be traps sorting layer.

01:02.480 --> 01:04.520
Let's give it a capsule collider.

01:04.520 --> 01:10.790
This time capsule Collider 2D because I think the shape is fitting the shape of the trap very well.

01:10.790 --> 01:11.960
So this is how it should be.

01:11.960 --> 01:16.160
And let's make it is trigger because this one going to damage the player.

01:16.730 --> 01:17.390
Yeah.

01:18.470 --> 01:20.840
Now we need an animator for this one.

01:20.840 --> 01:24.530
Let's go to animations, traps, controllers.

01:24.530 --> 01:29.060
Let's make animator controller trap fire.

01:29.060 --> 01:34.670
And also, while we are here, let's make animator for the button trap fire.

01:35.360 --> 01:36.200
Button.

01:36.200 --> 01:37.070
Okay.

01:37.220 --> 01:37.850
We're going to put.

01:37.880 --> 01:39.560
Trap fire on this one.

01:39.830 --> 01:42.320
And then we're going to make an animation.

01:42.320 --> 01:46.190
Let's go to assets animation traps.

01:46.190 --> 01:49.430
We're going to do trap fire active.

01:51.520 --> 01:54.490
When I go to graphics traps fire.

01:54.490 --> 01:56.980
Let's take on drag them here.

01:56.980 --> 01:58.540
Sample rate 20.

01:59.020 --> 02:00.340
Now there is a fire.

02:00.340 --> 02:02.290
We also need an off animation.

02:02.290 --> 02:04.840
So I'm going to do trap fire idle.

02:05.910 --> 02:07.560
I'm just going to drag it here.

02:07.560 --> 02:09.300
So now it's switched off.

02:09.330 --> 02:10.380
Very cool.

02:10.500 --> 02:15.120
Now we can go to animator itself and set up Boolean parameter bool.

02:15.730 --> 02:16.480
Active.

02:18.500 --> 02:23.330
Uh, we're going to transfer to idle if active is false.

02:23.330 --> 02:24.380
No exit time.

02:24.380 --> 02:26.180
Transition duration zero.

02:26.210 --> 02:27.860
Then we're going to transfer back.

02:28.860 --> 02:30.540
If active is true.

02:30.540 --> 02:30.810
Now.

02:30.810 --> 02:31.380
Exit time.

02:31.380 --> 02:32.910
Transition duration zero.

02:33.090 --> 02:35.640
Okay, job, fire is ready.

02:35.670 --> 02:37.230
Now let's make a button.

02:38.910 --> 02:40.350
Going to take one of the sprites.

02:40.350 --> 02:41.430
I want to take this one.

02:41.430 --> 02:42.540
Drag it here.

02:44.050 --> 02:45.760
And let's make it as Trump.

02:46.550 --> 02:50.090
Fire button and I'm going to make it as a child of a trap.

02:50.090 --> 02:50.570
Fire!

02:50.600 --> 02:51.440
Okay.

02:51.590 --> 02:55.370
We need animator controller, and I think we can just type here.

02:55.370 --> 02:56.900
Trap, fire.

02:57.620 --> 02:58.460
Uh, no, it's not there.

02:58.460 --> 03:00.500
Okay, let's add animator.

03:00.500 --> 03:02.090
Then we're going to open animator.

03:02.090 --> 03:06.290
Click over here and find this trap fire button.

03:06.710 --> 03:07.820
Okay cool.

03:08.120 --> 03:11.510
Let's make certain layer as a traps.

03:11.510 --> 03:15.260
Then on the animator we're going to make a couple of animations.

03:15.260 --> 03:21.860
Let's do create asset animations traps trap fire button.

03:21.860 --> 03:22.790
Uh idle.

03:22.790 --> 03:25.310
It's going to be just this sprite.

03:25.310 --> 03:29.150
And then one more trap fire button.

03:30.060 --> 03:31.440
Activated.

03:32.700 --> 03:37.290
And we're going to take all of the sprites, drag them here, make sample rate 20.

03:37.320 --> 03:38.520
Nice.

03:38.610 --> 03:42.510
Let's transfer to activate it with a trigger.

03:42.990 --> 03:44.130
Activate.

03:45.070 --> 03:47.290
So there's going to be condition for the transition.

03:47.290 --> 03:51.040
Activate transition duration zero exit time uncheck.

03:51.490 --> 03:54.610
Then we're going to go back over here and do.

03:56.000 --> 03:57.050
Exit time one.

03:57.050 --> 03:58.550
Transition duration zero.

03:58.580 --> 04:02.030
Now I'm doing nothing different from what we did before all of this.

04:02.030 --> 04:04.970
You know very well we did a bunch of traps, a bunch of setups.

04:04.970 --> 04:07.670
This is basically the same, just combination of what we learned.

04:07.670 --> 04:11.900
And I think I'm going to make this trap as a last one because it's time to move to another section.

04:11.900 --> 04:12.530
Yeah.

04:12.710 --> 04:14.960
Let's go to the scene.

04:17.390 --> 04:17.960
Yeah.

04:17.960 --> 04:20.780
On this button we need box collider so it can be triggered.

04:20.780 --> 04:22.250
Box Collider 2D.

04:22.430 --> 04:24.950
Let's set ease trigger over here.

04:25.400 --> 04:28.820
And this is probably all for the initial setup.

04:28.820 --> 04:31.040
This has a trigger collider okay.

04:31.040 --> 04:33.740
And this is a trap fire okay.

04:34.100 --> 04:36.230
Now let's go to scripts.

04:36.230 --> 04:39.200
And I think we can make a folder for the trap scripts.

04:41.580 --> 04:42.390
Trump's.

04:43.830 --> 04:46.470
Going to take the traps and drag them to the folder.

04:46.500 --> 04:51.000
Okay, now we're going to go inside and make two new scripts.

04:51.420 --> 04:52.830
One of them going to be.

04:53.960 --> 04:54.710
Trap.

04:55.580 --> 04:56.270
Fire.

04:57.140 --> 05:00.020
Another one going to be I is going to pop up now.

05:00.020 --> 05:02.030
I hate it, I know it's fine.

05:02.030 --> 05:06.500
Another one going to be trap fire button.

05:09.730 --> 05:10.090
Okay.

05:10.090 --> 05:11.290
This is what we have now.

05:11.290 --> 05:13.300
We're going to select Trapwire button.

05:13.390 --> 05:14.920
Give it a script.

05:14.920 --> 05:19.990
And on the trapwire we're going to select I mean put Trapwire okay.

05:19.990 --> 05:22.060
Now let's go inside of the scripts.

05:22.060 --> 05:26.380
You're going to need trap and trap fire button on the trap itself.

05:26.380 --> 05:32.440
We're going to make a method that would activate the fire or deactivate the fire according to the boolean

05:32.440 --> 05:33.520
we pass in there.

05:33.790 --> 05:40.690
So I'm going to do private void set fire bool active.

05:41.910 --> 05:45.360
And now we need to change a bunch of parameters according to the boolean we have.

05:45.390 --> 05:47.640
So one of them would be animation.

05:47.640 --> 05:49.860
So private animator anim.

05:50.760 --> 05:55.140
Also, there is a capsule collider because if we don't switch it off, we still can be damaged.

05:56.020 --> 05:57.250
Let's do Collider.

05:57.460 --> 05:58.060
We cannot do that.

05:58.060 --> 05:58.690
Okay.

05:58.990 --> 06:00.400
Wire Collider.

06:00.400 --> 06:01.840
And we.

06:02.290 --> 06:08.410
I think we just need a boolean private bool to know if wire is active is active.

06:08.410 --> 06:10.930
Then in this method we're going to do this.

06:11.840 --> 06:20.390
Um, we can just do enum set bool of active to active that we pass in through the parentheses.

06:20.390 --> 06:26.450
We can also do fire collider enabled equals to active and is active equals to active.

06:26.450 --> 06:27.500
Just like that.

06:27.800 --> 06:29.510
Now let's.

06:30.440 --> 06:33.860
Now make a coroutine that would switch off the fire.

06:33.890 --> 06:36.530
Wait for the cooldown and switch it on.

06:36.950 --> 06:41.210
Right, we need a cooldown itself, so I'm going to do serialize field private float.

06:41.240 --> 06:43.280
Let's do off duration.

06:43.990 --> 06:46.720
And then there's going to be enumerator.

06:47.940 --> 06:49.650
Via coroutine.

06:50.360 --> 06:51.800
Let's type here private.

06:51.800 --> 06:53.000
So it's pretty.

06:53.180 --> 06:54.980
Then we're going to do set fire.

06:55.900 --> 06:58.180
Pulse, it's going to switch it off.

06:58.180 --> 06:58.870
Then we're going to do.

06:58.900 --> 06:59.200
Yield.

06:59.200 --> 07:00.550
Return new.

07:00.550 --> 07:03.460
Wait for a seconds of duration.

07:03.460 --> 07:04.930
Then we're going to do set fire.

07:04.960 --> 07:05.350
True.

07:05.350 --> 07:06.910
So we're going to switch it on.

07:06.970 --> 07:09.730
Also we want to switch on the fire at the start.

07:09.730 --> 07:12.130
So I'm going to do start set fire.

07:12.130 --> 07:12.940
True.

07:12.940 --> 07:16.810
And also we want to get these components in the wake.

07:17.020 --> 07:18.730
So I'm going to do a wake.

07:19.560 --> 07:22.200
Einem Getcomponent via Collider.

07:22.230 --> 07:24.240
Getcomponent of a capsule collider.

07:24.240 --> 07:25.740
This is perfect.

07:25.980 --> 07:28.290
Now what we need or I'm so sorry.

07:28.290 --> 07:30.330
Now what we need is to.

07:31.800 --> 07:35.580
Let me somehow move it closer so you can see everything together.

07:39.330 --> 07:40.110
Yes, this will do.

07:40.200 --> 07:43.650
Now we need to call this coroutine.

07:43.650 --> 07:47.040
We need to start this coroutine from outside of this script.

07:47.040 --> 07:51.690
We want to start this coroutine when player enters the button trigger.

07:51.690 --> 07:55.890
And also, just in case, I want to be sure there is always a fire button.

07:55.890 --> 07:58.380
So I want to make a reference to a.

07:59.350 --> 08:00.400
The serialized field.

08:00.400 --> 08:01.870
Private trap.

08:01.870 --> 08:03.100
Fire button.

08:03.550 --> 08:05.080
Fire button.

08:05.080 --> 08:09.880
And then in the start over here, I'm going to check if fire button equals to null.

08:09.880 --> 08:12.250
Then I'm going to do debug log warning.

08:13.300 --> 08:16.780
You don't have fire button.

08:17.480 --> 08:18.110
On.

08:19.170 --> 08:19.710
Last game.

08:19.710 --> 08:20.880
Objectname.

08:20.880 --> 08:23.250
And basically that's just it.

08:23.250 --> 08:24.660
Let's just do it like that.

08:24.660 --> 08:27.660
So it's going to give us a message if we're missing a fire button.

08:28.500 --> 08:30.540
And let's make a public method.

08:31.380 --> 08:37.230
Public void switch off fire, which would do just startcoroutine.

08:37.260 --> 08:38.940
Of a fire coroutine.

08:39.480 --> 08:40.530
Nice.

08:40.650 --> 08:41.850
This is ready.

08:42.210 --> 08:43.980
So this one is pretty simple, I guess.

08:43.980 --> 08:46.260
Much easier than things we did before.

08:46.440 --> 08:48.360
Now let's go to trap fire button.

08:48.900 --> 08:49.830
Over here.

08:49.830 --> 08:51.390
We want to get a reference.

08:51.390 --> 08:53.340
Private trap fire!

08:53.970 --> 08:54.990
Trap fire.

08:54.990 --> 08:58.140
And we need animator private animator anim.

08:58.140 --> 09:06.840
Then in the wake, we can do anim and then trap fire equals to getcomponent in parent of a trap fire.

09:06.870 --> 09:07.800
Nice.

09:07.800 --> 09:09.120
Then we need on trigger.

09:09.120 --> 09:10.050
Enter 2D.

09:11.440 --> 09:13.720
And we're going to check player.

09:13.720 --> 09:18.940
Player equals to collision game beam object player.

09:18.940 --> 09:24.280
If player not equals to null then anim set trigger of activate.

09:24.280 --> 09:31.390
So we activate the buttons animation and we take trap fire and ask it to switch off the fire.

09:31.420 --> 09:33.640
All right that's all what we need.

09:34.060 --> 09:40.150
I think I'm going to clean it up also, just in case when I show you script here.

09:42.310 --> 09:44.440
Maybe let's squeeze it like so.

09:49.170 --> 09:51.000
Oh is active is not used.

09:51.000 --> 09:51.630
Yeah.

09:51.660 --> 09:53.520
Actually, let's go to this method.

09:54.190 --> 09:55.540
And type this.

09:57.360 --> 09:58.260
Sorry.

09:58.980 --> 09:59.190
Like.

09:59.190 --> 10:07.260
So if is active, then return button cannot be activated if fire is active already.

10:07.260 --> 10:08.010
Okay.

10:08.610 --> 10:12.480
Well button will be activated, but we will not be able to start a coroutine.

10:12.480 --> 10:13.590
Let's go back.

10:16.650 --> 10:17.160
Over here.

10:17.160 --> 10:19.230
We want to assign trap fire button.

10:19.230 --> 10:22.440
Let's make duration maybe 2.5 seconds.

10:22.740 --> 10:24.210
And the fire button itself.

10:24.210 --> 10:27.150
I think we don't need anything else on the trap.

10:27.150 --> 10:27.600
Fire.

10:27.600 --> 10:29.490
I think we need the image trigger.

10:29.640 --> 10:30.360
Okay.

10:30.360 --> 10:31.320
Very cool.

10:31.320 --> 10:33.540
Now, let's say you need a prefab of this.

10:33.540 --> 10:35.640
You can just make it as a prefab.

10:35.640 --> 10:41.580
And next time you need a trap fire, you just have to take the trap fire on the level, place it where

10:41.580 --> 10:42.510
you want it to be.

10:42.510 --> 10:48.270
For example, I want to place it over here, and then you take the button itself and move it somewhere,

10:48.270 --> 10:50.700
and you just place the button over here.

10:51.120 --> 10:54.090
Now we're going to go to the game mode.

10:56.860 --> 10:59.530
Let's say I fell over here.

10:59.530 --> 11:01.270
There is my fire trap.

11:03.060 --> 11:04.320
Gonna go ahead.

11:05.990 --> 11:07.250
Activate the button.

11:07.250 --> 11:12.800
Oh, animation is activated, but fire is not switching off.

11:13.710 --> 11:15.240
Oh, let me see why.

11:18.010 --> 11:18.460
Probably.

11:18.460 --> 11:19.540
I made a mistake.

11:21.970 --> 11:23.020
Yeah, this one should be.

11:23.020 --> 11:27.220
If is active false, then return.

11:27.220 --> 11:27.850
Okay.

11:30.650 --> 11:31.910
Let me try again.

11:38.040 --> 11:39.210
Now there is some.

11:39.210 --> 11:40.020
It's okay.

11:40.020 --> 11:40.890
Doesn't matter.

11:43.890 --> 11:47.850
Switched off the fire running and boom, fire is on.

11:48.090 --> 11:51.870
There is a damage, so I have to switch it off before I go further.

11:52.850 --> 11:54.830
Really nice, I like it.

12:06.430 --> 12:08.080
Turn turn, turn.

12:10.420 --> 12:12.730
Well, this could be a fun game, honestly.

12:13.090 --> 12:16.750
Okay, that's it for this video and let's go to the next one.
