1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:04,000
In this video, we're going to make a trap, and it's going to be as easy as making a coin.

3
00:00:04,000 --> 00:00:07,000
Let's create a 2D Sprite.

4
00:00:08,000 --> 00:00:10,000
Asymmetric diamond.

5
00:00:11,000 --> 00:00:13,000
I'm going to name it as Trump.

6
00:00:16,000 --> 00:00:17,000
Let me find it.

7
00:00:17,000 --> 00:00:26,000
Certainly there can be enemy and just minus one over here, and I'll try to rotate it like this.

8
00:00:27,000 --> 00:00:29,000
Basically rotation just 90 on this Z.

9
00:00:30,000 --> 00:00:37,000
I want to make it red color so it looks dangerous and add a collider box collider to DX.

10
00:00:37,000 --> 00:00:42,000
Let's adjust the size just by a bit to something like this.

11
00:00:43,000 --> 00:00:47,000
And now next step would be triggering action on entering the box.

12
00:00:47,000 --> 00:00:49,000
Collider We need to check.

13
00:00:49,000 --> 00:00:51,000
This box is Trigger, of course.

14
00:00:51,000 --> 00:00:54,000
And now I'm going to add a script.

15
00:00:55,000 --> 00:00:57,000
New script trap.

16
00:00:57,000 --> 00:01:04,000
Just as a small task here, without my help, try to do on trigger enter and just debug a line like

17
00:01:05,000 --> 00:01:06,000
player was knocked or something.

18
00:01:06,000 --> 00:01:07,000
Go and do that.

19
00:01:08,000 --> 00:01:11,000
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.

20
00:01:13,000 --> 00:01:13,000
One, two.

21
00:01:14,000 --> 00:01:14,000
Okay.

22
00:01:14,000 --> 00:01:19,000
So what we're going to do here is first set in and trigger enter.

23
00:01:20,000 --> 00:01:23,000
And before we continue, let's go to player.

24
00:01:23,000 --> 00:01:26,000
And below the update, I'm going to create a public function.

25
00:01:26,000 --> 00:01:29,000
It should be public so I can get access to it.

26
00:01:29,000 --> 00:01:32,000
Public void damage.

27
00:01:32,000 --> 00:01:34,000
So damage for the player.

28
00:01:34,000 --> 00:01:39,000
And what I want to do here is to check if speed is equals to maximum.

29
00:01:39,000 --> 00:01:40,000
If speed.

30
00:01:41,000 --> 00:01:42,000
What was that move?

31
00:01:42,000 --> 00:01:42,000
Speed.

32
00:01:44,000 --> 00:01:45,000
Equals to max speed.

33
00:01:46,000 --> 00:01:49,000
Actually, let's use bigger or equals just in case.

34
00:01:49,000 --> 00:01:50,000
Equals or bigger to max speed.

35
00:01:50,000 --> 00:01:52,000
Then I'm going to do a knockback.

36
00:01:54,000 --> 00:01:55,000
Else.

37
00:01:55,000 --> 00:01:59,000
So if it's not bigger or equal to maximum speed, it is less.

38
00:01:59,000 --> 00:02:01,000
Then I'm going to call just die.

39
00:02:01,000 --> 00:02:09,000
So the idea here is to give a player a second chance when he has maximum speed, but if he doesn't have

40
00:02:09,000 --> 00:02:10,000
anything, he should die.

41
00:02:10,000 --> 00:02:14,000
If you played any games like Subway Surfer, you might remember that.

42
00:02:14,000 --> 00:02:17,000
If I remember it correctly, you can run for some amount of time.

43
00:02:17,000 --> 00:02:20,000
If you bump into something, you lose in speed.

44
00:02:20,000 --> 00:02:22,000
If you bump again, you lose your game.

45
00:02:23,000 --> 00:02:26,000
That's how it works and that's what we're doing here.

46
00:02:26,000 --> 00:02:31,000
And actually with our set up that we have from before, very easy to set up, right?

47
00:02:32,000 --> 00:02:34,000
Now let's go back to our trap.

48
00:02:34,000 --> 00:02:37,000
And here I'm going to check for component of the player.

49
00:02:38,000 --> 00:02:46,000
If collision dot get component of a player not equals to null, then we're going to do collision dot

50
00:02:46,000 --> 00:02:48,000
get component of a player.

51
00:02:49,000 --> 00:02:51,000
And we're going to call damage function.

52
00:02:54,000 --> 00:02:55,000
Now I'm going to go back.

53
00:02:56,000 --> 00:02:59,000
I'll make a prefab for this trap like this.

54
00:03:01,000 --> 00:03:04,000
And then I'm going to go to level part.

55
00:03:04,000 --> 00:03:06,000
Delete my coin generators from here.

56
00:03:07,000 --> 00:03:08,000
Place a couple of traps.

57
00:03:08,000 --> 00:03:10,000
One here.

58
00:03:10,000 --> 00:03:12,000
Oh, it's really feasible here.

59
00:03:12,000 --> 00:03:13,000
I don't like it.

60
00:03:13,000 --> 00:03:15,000
Let's change something.

61
00:03:15,000 --> 00:03:17,000
Let's open prefab of the trap like this.

62
00:03:17,000 --> 00:03:22,000
Find spread, render and change certain layer from enemy to platform.

63
00:03:22,000 --> 00:03:25,000
So it will be behind the platform by clicking this icon.

64
00:03:25,000 --> 00:03:26,000
You going back?

65
00:03:26,000 --> 00:03:28,000
Now let's go to level part again.

66
00:03:29,000 --> 00:03:30,000
Now it is behind the platform.

67
00:03:31,000 --> 00:03:35,000
I'm going to place it like this duplicate and place another one.

68
00:03:36,000 --> 00:03:37,000
Somewhere here.

69
00:03:37,000 --> 00:03:39,000
Now I'm going to test it.

70
00:03:43,000 --> 00:03:45,000
And how it's supposed to work.

71
00:03:45,000 --> 00:03:49,000
If I'll bump into Trump right now, I'll get death of the character.

72
00:03:51,000 --> 00:03:52,000
Hey, it's not working.

73
00:03:54,000 --> 00:03:54,000
Hmm.

74
00:03:55,000 --> 00:03:55,000
Let's see.

75
00:03:55,000 --> 00:03:56,000
Why is that?

76
00:04:01,000 --> 00:04:03,000
Box collider is trigger.

77
00:04:05,000 --> 00:04:06,000
Let's see the code.

78
00:04:14,000 --> 00:04:15,000
What is going on?

79
00:04:15,000 --> 00:04:16,000
I don't understand.

80
00:04:16,000 --> 00:04:19,000
Let's debug line and see if we enter in the trigger at all.

81
00:04:20,000 --> 00:04:21,000
Enter trigger.

82
00:04:23,000 --> 00:04:25,000
So it's not about trigger, it's about function.

83
00:04:25,000 --> 00:04:28,000
We created what's wrong with the function?

84
00:04:29,000 --> 00:04:32,000
Public void if cells die.

85
00:04:36,000 --> 00:04:38,000
Oh, I'm sorry.

86
00:04:38,000 --> 00:04:39,000
Of course.

87
00:04:39,000 --> 00:04:40,000
My bad.

88
00:04:40,000 --> 00:04:40,000
Yeah.

89
00:04:40,000 --> 00:04:44,000
We should start quoting here, not just type die.

90
00:04:44,000 --> 00:04:46,000
So please forgive me for this.

91
00:04:46,000 --> 00:04:49,000
So should be start quarantine.

92
00:04:49,000 --> 00:04:50,000
I don't know.

93
00:04:50,000 --> 00:04:53,000
How could I forget this and just do this?

94
00:04:53,000 --> 00:04:53,000
Start quarantine.

95
00:04:53,000 --> 00:04:55,000
So else, start quarantine.

96
00:04:55,000 --> 00:04:56,000
Die.

97
00:04:56,000 --> 00:04:57,000
Because this is a quarantine.

98
00:04:58,000 --> 00:04:59,000
Let's go now.

99
00:04:59,000 --> 00:05:01,000
And it's going to be fine.

100
00:05:02,000 --> 00:05:06,000
Also, I changed the trigger collider just in case because of the collider.

101
00:05:06,000 --> 00:05:08,000
But it's not, so I'll change it back.

102
00:05:12,000 --> 00:05:15,000
Okay, So, boom, I died.

103
00:05:15,000 --> 00:05:18,000
What if I try to jump over and get maximum speed?

104
00:05:18,000 --> 00:05:19,000
Will I die?

105
00:05:19,000 --> 00:05:20,000
Let's see.

106
00:05:20,000 --> 00:05:20,000
I move.

107
00:05:20,000 --> 00:05:21,000
Speed is 12.

108
00:05:22,000 --> 00:05:24,000
Getting some speed now.

109
00:05:27,000 --> 00:05:32,000
So it's 20 and just the knockback and death.

110
00:05:32,000 --> 00:05:33,000
Cool.

111
00:05:33,000 --> 00:05:34,000
I like it.

112
00:05:36,000 --> 00:05:40,000
I'm sorry if we stumbled on a mistake there, but it's a development.

113
00:05:40,000 --> 00:05:41,000
You cannot avoid it.

114
00:05:41,000 --> 00:05:43,000
Even if you planned everything perfectly.

115
00:05:43,000 --> 00:05:46,000
Sometimes you forget things and it's okay.

116
00:05:46,000 --> 00:05:48,000
It's completely normal, I guess.

117
00:05:48,000 --> 00:05:53,000
Honestly, when you develop in a game, nothing goes as smooth as a show.

118
00:05:53,000 --> 00:05:56,000
When you hear you stumble.

119
00:05:56,000 --> 00:05:59,000
It's so many things before you find the right way to make it work.

120
00:05:59,000 --> 00:06:04,000
So if you have some trouble on making a game, please don't worry about it.

121
00:06:04,000 --> 00:06:04,000
Just try.

122
00:06:04,000 --> 00:06:07,000
Try until you find a solution and it will be fine.

123
00:06:08,000 --> 00:06:09,000
So let's go to next video now.

124
00:06:10,000 --> 00:06:10,000
See you.

