1
00:00:00,000 --> 00:00:02,960
Welcome back, my fellow game developers.

2
00:00:02,955 --> 00:00:05,925
As you can see, we've created some spikes in here.

3
00:00:05,925 --> 00:00:08,195
So now when we have these bikes,

4
00:00:08,190 --> 00:00:10,080
if I stand on them, there we go.

5
00:00:10,080 --> 00:00:13,310
I get damaged. And if I stand and go back,

6
00:00:13,305 --> 00:00:14,435
I don't get damaged.

7
00:00:14,430 --> 00:00:17,750
And if I stand and keep standing, I get damaged.

8
00:00:17,745 --> 00:00:19,575
But now because I'm still invincible,

9
00:00:19,575 --> 00:00:20,805
I get damaged again.

10
00:00:20,805 --> 00:00:22,335
If I keep standing in here,

11
00:00:22,335 --> 00:00:23,475
so I might die,

12
00:00:23,475 --> 00:00:24,915
I'm going to go away a bit

13
00:00:24,915 --> 00:00:26,985
and let's not waste any more time.

14
00:00:26,985 --> 00:00:29,505
And let's get started.

15
00:00:29,620 --> 00:00:34,400
Oh, okay, so let's get to spike creation.

16
00:00:34,400 --> 00:00:37,150
And I've already created the spikes and everything.

17
00:00:37,145 --> 00:00:40,345
Now, this is something that I do not like to do.

18
00:00:40,340 --> 00:00:43,130
I don't like to do things off screen and then tell you,

19
00:00:43,130 --> 00:00:45,230
but because I wanted to make sure that

20
00:00:45,230 --> 00:00:47,720
this video is as efficient as possible,

21
00:00:47,720 --> 00:00:50,960
It's a long and somethings will need to be explained.

22
00:00:50,960 --> 00:00:52,160
So for that reason,

23
00:00:52,160 --> 00:00:54,850
I created all the animations and so on.

24
00:00:54,845 --> 00:00:56,155
I'll just give you a quick tour.

25
00:00:56,150 --> 00:00:57,800
So what I did, I chose one of

26
00:00:57,800 --> 00:00:59,870
these three traps right here.

27
00:00:59,870 --> 00:01:01,600
I went back in the game.

28
00:01:01,595 --> 00:01:03,085
I selected the sprites,

29
00:01:03,080 --> 00:01:05,380
I'm sure it's 32 multiple,

30
00:01:05,375 --> 00:01:09,815
made sure to edit the sprite and sliced up 32 by 32,

31
00:01:09,815 --> 00:01:13,525
made the filter, and so on.

32
00:01:13,520 --> 00:01:16,460
I then went ahead and created this spike trap,

33
00:01:16,460 --> 00:01:17,930
which has a sprite renderer.

34
00:01:17,930 --> 00:01:19,940
A animator will get to that and

35
00:01:19,940 --> 00:01:22,250
a box collider that is just around it,

36
00:01:22,250 --> 00:01:24,020
which is also a trigger because we

37
00:01:24,020 --> 00:01:25,820
want the player to walk over it.

38
00:01:25,820 --> 00:01:26,480
Okay?

39
00:01:26,480 --> 00:01:29,750
Now I created also an animation for the spike.

40
00:01:29,750 --> 00:01:32,630
One is idle, one is popping,

41
00:01:32,630 --> 00:01:34,940
so the idle just stands there, does nothing.

42
00:01:34,940 --> 00:01:36,800
This will be the default animation.

43
00:01:36,800 --> 00:01:39,070
And then we have the spikes popping,

44
00:01:39,065 --> 00:01:40,675
which is in here.

45
00:01:40,670 --> 00:01:43,790
You'll see I created one to pop this private.

46
00:01:43,790 --> 00:01:45,440
So there you go. You can see,

47
00:01:45,440 --> 00:01:47,180
and why would I make it a bit slow?

48
00:01:47,180 --> 00:01:49,550
I just wanted to give a chance to the player

49
00:01:49,550 --> 00:01:52,220
to think twice before stepping on there again.

50
00:01:52,220 --> 00:01:54,370
So it has nothing to do with

51
00:01:54,365 --> 00:01:55,615
the player wants the player

52
00:01:55,610 --> 00:01:57,170
stops and it starts triggering.

53
00:01:57,170 --> 00:01:59,450
And then he has a couple of frames.

54
00:01:59,450 --> 00:02:01,360
Can move this right here.

55
00:02:01,355 --> 00:02:03,385
He has a couple of frames to realize

56
00:02:03,380 --> 00:02:05,990
his mistake and then try to run away from it.

57
00:02:05,990 --> 00:02:07,280
With that out of the way,

58
00:02:07,280 --> 00:02:09,760
let's talk about the animator and what we've done here.

59
00:02:09,755 --> 00:02:11,335
So I created the ival,

60
00:02:11,330 --> 00:02:13,490
made it the default layer state,

61
00:02:13,490 --> 00:02:15,740
and then created the two transitions,

62
00:02:15,740 --> 00:02:18,280
one going 21, going from.

63
00:02:18,275 --> 00:02:20,795
I also created a parameter in here which

64
00:02:20,795 --> 00:02:23,415
is a boolean for the BOP spikes.

65
00:02:23,419 --> 00:02:26,469
And once the pop spikes is true,

66
00:02:26,465 --> 00:02:29,855
then we go from idle to Pops spikes.

67
00:02:29,855 --> 00:02:31,915
We don't have any transition duration,

68
00:02:31,910 --> 00:02:33,880
we don't have any exit time.

69
00:02:33,875 --> 00:02:36,905
But when we are going back from the bopping,

70
00:02:36,905 --> 00:02:38,665
we do have an exit time which is

71
00:02:38,660 --> 00:02:40,910
about 90 percent of the animation.

72
00:02:40,910 --> 00:02:43,550
We can even increase it to one maybe until

73
00:02:43,550 --> 00:02:46,480
we finish the entire animation and then we go back.

74
00:02:46,475 --> 00:02:48,745
I am rather make it 0.57.

75
00:02:48,740 --> 00:02:51,220
But for some reason when I set it for this,

76
00:02:51,215 --> 00:02:53,035
the animation in here disappears.

77
00:02:53,030 --> 00:02:55,780
I'm really confused why this is happening.

78
00:02:55,775 --> 00:02:57,235
I don't like it at all.

79
00:02:57,230 --> 00:03:00,160
So 92 maybe in 1906.

80
00:03:00,155 --> 00:03:02,515
1907 just makes everything disappear,

81
00:03:02,510 --> 00:03:04,220
which is extremely annoying.

82
00:03:04,220 --> 00:03:06,380
And I have no idea why this is happening.

83
00:03:06,380 --> 00:03:08,300
But anyways, we have an exit time

84
00:03:08,300 --> 00:03:10,550
which is 96 percent of the animation.

85
00:03:10,550 --> 00:03:13,040
Then we go back. Well that out of the way,

86
00:03:13,040 --> 00:03:14,990
if you do one, pause the video right now,

87
00:03:14,990 --> 00:03:16,940
go do everything for that.

88
00:03:16,940 --> 00:03:19,100
Create all the animations and so on.

89
00:03:19,100 --> 00:03:21,890
Because I'm going to go ahead and start

90
00:03:21,890 --> 00:03:25,840
in the scripts by creating a,

91
00:03:25,835 --> 00:03:28,825
let's call this folder the traps.

92
00:03:28,820 --> 00:03:31,190
Maybe you'll want to create multiple traps.

93
00:03:31,190 --> 00:03:34,980
And in here I'm going to create the spikes.

94
00:03:34,984 --> 00:03:37,714
So right-click, create the C-sharp,

95
00:03:37,715 --> 00:03:41,065
and let's make it the spikes hit Enter,

96
00:03:41,060 --> 00:03:43,610
select the spike trap.

97
00:03:43,610 --> 00:03:46,520
And I'm going to drag these parks in here.

98
00:03:46,520 --> 00:03:48,220
Now I'm going to double-click and

99
00:03:48,215 --> 00:03:50,215
open it up and Visual Studio.

100
00:03:50,210 --> 00:03:52,130
Now, before we continue on,

101
00:03:52,130 --> 00:03:53,270
let me just explain

102
00:03:53,270 --> 00:03:56,390
what the main idea or how this spike is going to work.

103
00:03:56,390 --> 00:03:59,150
Because in just a bit I'm going to issue the challenge

104
00:03:59,150 --> 00:04:02,240
and I want you to know how the spike will work.

105
00:04:02,240 --> 00:04:04,430
So the player is walking around,

106
00:04:04,430 --> 00:04:07,790
whereas the player, they don't player is walking around.

107
00:04:07,790 --> 00:04:11,140
Then suddenly while the spikes are hidden, hidden,

108
00:04:11,135 --> 00:04:14,635
he walks over on the spikes and they start popping out.

109
00:04:14,630 --> 00:04:16,190
So when they do hit him,

110
00:04:16,190 --> 00:04:18,200
what we want is we want

111
00:04:18,200 --> 00:04:20,450
the animation to have some kind of

112
00:04:20,450 --> 00:04:24,920
event system and that event system will damage the blade.

113
00:04:24,920 --> 00:04:26,450
So we'll need to have

114
00:04:26,450 --> 00:04:28,870
the damage amount variable will have to get

115
00:04:28,865 --> 00:04:31,105
a reference to that layer and we

116
00:04:31,100 --> 00:04:33,860
have to add an event in here that will damage him.

117
00:04:33,860 --> 00:04:35,780
We also want to make sure that if

118
00:04:35,780 --> 00:04:38,240
the player is still standing on the spikes,

119
00:04:38,240 --> 00:04:40,240
we want to keep damaging him.

120
00:04:40,235 --> 00:04:42,925
Not just get damaged

121
00:04:42,920 --> 00:04:46,300
once and then skip standing in here and not feel a thing.

122
00:04:46,295 --> 00:04:48,415
We also want to make sure that when the player

123
00:04:48,410 --> 00:04:50,860
activates the spikes, he goes away.

124
00:04:50,855 --> 00:04:54,325
We don't want him to keep getting damaged because while

125
00:04:54,320 --> 00:04:56,360
the animation of the spikes is

126
00:04:56,360 --> 00:04:59,140
working and events system will still get triggered,

127
00:04:59,135 --> 00:05:00,295
or you'll see how everything is

128
00:05:00,290 --> 00:05:02,630
working when we actually create that.

129
00:05:02,630 --> 00:05:05,330
But until then, I'm going to issue a challenge

130
00:05:05,330 --> 00:05:07,990
to damage the deep layer with spikes.

131
00:05:07,985 --> 00:05:11,275
So first of all, create a variable for the damage and

132
00:05:11,270 --> 00:05:13,040
the player we should damage

133
00:05:13,040 --> 00:05:15,400
will need to create the entrepreneur Enter.

134
00:05:15,395 --> 00:05:16,975
You'll need to start the animation

135
00:05:16,970 --> 00:05:18,230
and make sure it stops.

136
00:05:18,230 --> 00:05:20,420
So make sure it stops means that we

137
00:05:20,420 --> 00:05:23,320
may need and on sugar exit.

138
00:05:23,315 --> 00:05:24,745
Then you'll need damage

139
00:05:24,740 --> 00:05:26,500
the player using the event system.

140
00:05:26,495 --> 00:05:27,925
And finally, I just want you to

141
00:05:27,920 --> 00:05:29,720
think of what should happen if

142
00:05:29,720 --> 00:05:33,050
the blur stays on the spikes and then exits.

143
00:05:33,050 --> 00:05:34,790
So with that out of the way,

144
00:05:34,790 --> 00:05:39,590
pause the video right now and go do the challenge.

145
00:05:39,590 --> 00:05:41,660
Okay, welcome back.

146
00:05:41,660 --> 00:05:43,790
So back in our script in here,

147
00:05:43,790 --> 00:05:45,520
we are going to get, first of all,

148
00:05:45,515 --> 00:05:48,235
a serialized field which is going to be of

149
00:05:48,230 --> 00:05:53,980
type integer and the damage amount.

150
00:05:53,975 --> 00:05:57,955
Then we are going to create a private void.

151
00:05:57,950 --> 00:06:00,940
And there's no excuse me, not a private void,

152
00:06:00,935 --> 00:06:03,505
a private collider 2D,

153
00:06:03,500 --> 00:06:07,270
and this will be the player to damage.

154
00:06:07,265 --> 00:06:08,395
Save that.

155
00:06:08,390 --> 00:06:10,570
Now I'm going to remove the start and

156
00:06:10,565 --> 00:06:13,135
update if we do need them later on, we can add them.

157
00:06:13,130 --> 00:06:14,420
It's pretty simple.

158
00:06:14,420 --> 00:06:17,980
I'm going to create the On Trigger Enter to D.

159
00:06:17,975 --> 00:06:20,185
I'm going to check if this

160
00:06:20,180 --> 00:06:27,560
collision.com tag is the layer.

161
00:06:27,560 --> 00:06:31,000
If it is, then I'm going to get the component which

162
00:06:30,995 --> 00:06:34,585
is the ending main door.

163
00:06:34,580 --> 00:06:38,720
And I'm going to go ahead and set the bool,

164
00:06:38,720 --> 00:06:41,260
which is going to be the letter

165
00:06:41,255 --> 00:06:42,955
because this is a string reference.

166
00:06:42,950 --> 00:06:46,250
We are going to get this bikes.

167
00:06:46,250 --> 00:06:48,440
Bob spikes, copy that.

168
00:06:48,440 --> 00:06:50,200
And back in here.

169
00:06:50,195 --> 00:06:52,145
And let's set this pops.

170
00:06:52,145 --> 00:06:54,265
Bikes, save that.

171
00:06:54,260 --> 00:06:56,960
And then we'll create a method in

172
00:06:56,960 --> 00:06:59,630
here which is going to be to damage the player,

173
00:06:59,630 --> 00:07:04,960
which is a public void damage layer.

174
00:07:04,955 --> 00:07:08,855
And also we need to set this to true.

175
00:07:08,855 --> 00:07:10,145
Save that.

176
00:07:10,145 --> 00:07:12,335
So we are going to damage the player.

177
00:07:12,335 --> 00:07:14,035
What should we be doing in here?

178
00:07:14,030 --> 00:07:16,480
We are just going to get the player to

179
00:07:16,475 --> 00:07:19,505
damage dot get component,

180
00:07:19,505 --> 00:07:22,795
the player health handler.

181
00:07:22,790 --> 00:07:24,950
And we are going to go ahead and

182
00:07:24,950 --> 00:07:28,690
damage layer with the amount of damage.

183
00:07:28,685 --> 00:07:30,655
And before we forget,

184
00:07:30,650 --> 00:07:32,660
how are we going to get access to

185
00:07:32,660 --> 00:07:36,290
this layer damage when the player steps in here?

186
00:07:36,290 --> 00:07:38,140
What's the problem in here?

187
00:07:38,135 --> 00:07:39,875
Amount of donors not exist.

188
00:07:39,875 --> 00:07:41,435
Oh, so sorry.

189
00:07:41,435 --> 00:07:42,955
Damage amount.

190
00:07:42,950 --> 00:07:45,200
Where did I get the amount of damage?

191
00:07:45,200 --> 00:07:47,660
I'm not even sure anyways, in here,

192
00:07:47,660 --> 00:07:49,510
the player to damage

193
00:07:49,505 --> 00:07:52,015
is going to be equal to the collision.

194
00:07:52,010 --> 00:07:53,240
There we go.

195
00:07:53,240 --> 00:07:55,040
So on Trigger Enter,

196
00:07:55,040 --> 00:07:56,680
we check, is it the player?

197
00:07:56,675 --> 00:07:59,995
Yes, we start the pop spikes animation.

198
00:07:59,990 --> 00:08:01,820
Then we set the player to

199
00:08:01,820 --> 00:08:04,250
damage as the collision because it's declared,

200
00:08:04,250 --> 00:08:07,480
we know that then we are going to damage the player.

201
00:08:07,475 --> 00:08:09,805
And finally, we are going to go back in here.

202
00:08:09,800 --> 00:08:11,240
What's the problem?

203
00:08:11,240 --> 00:08:13,640
Okay? Nothing animation and we are

204
00:08:13,640 --> 00:08:16,460
going to select in the scene.

205
00:08:16,455 --> 00:08:17,475
So there you go.

206
00:08:17,470 --> 00:08:21,000
We can see that it starts off, then nothing happens.

207
00:08:20,995 --> 00:08:24,195
And a couple of seconds we wait and then we book in here,

208
00:08:24,190 --> 00:08:26,470
I'm going to add the event

209
00:08:26,470 --> 00:08:30,060
and I'm going to select to damage the player.

210
00:08:30,055 --> 00:08:33,985
We're going to save that to run the game.

211
00:08:33,985 --> 00:08:36,615
And we shall see in here that we have a life

212
00:08:36,610 --> 00:08:39,060
of 600 once I stop on these bikes.

213
00:08:39,055 --> 00:08:40,105
Yep. There we go.

214
00:08:40,105 --> 00:08:41,915
It damages us.

215
00:08:41,919 --> 00:08:46,449
It doesn't damage us because if I go back to the spikes,

216
00:08:46,450 --> 00:08:48,600
we don't have anything to damage.

217
00:08:48,595 --> 00:08:53,605
Let's just set it as 100 for now because the life is 600.

218
00:08:53,605 --> 00:08:55,575
So I think he can take a couple of hits.

219
00:08:55,570 --> 00:08:58,700
So now we have the spikes.

220
00:08:58,695 --> 00:08:59,815
Yep, there we go.

221
00:08:59,810 --> 00:09:02,960
You can see that it removes 100 every single time.

222
00:09:02,960 --> 00:09:04,130
And because we have this

223
00:09:04,130 --> 00:09:05,870
invincibility for a couple of seconds,

224
00:09:05,870 --> 00:09:08,660
the second tip doesn't affect the layer.

225
00:09:08,660 --> 00:09:10,850
But the problem is,

226
00:09:10,850 --> 00:09:12,950
you can see that it keeps

227
00:09:12,950 --> 00:09:15,200
playing and I keep getting damaged.

228
00:09:15,200 --> 00:09:18,010
So the player died even though he's standing

229
00:09:18,005 --> 00:09:21,665
outside the perimeter of the sparks.

230
00:09:21,665 --> 00:09:24,425
So what we should be doing is first of all,

231
00:09:24,425 --> 00:09:29,435
we need to be stopping the animation On Trigger exit 2D.

232
00:09:29,435 --> 00:09:31,045
And in here, I'm just going to do

233
00:09:31,040 --> 00:09:32,920
the same thing I did in here.

234
00:09:32,915 --> 00:09:34,595
Check for the player.

235
00:09:34,595 --> 00:09:38,555
And if it is the player that just exited the collision,

236
00:09:38,555 --> 00:09:40,705
we are going to set this to False,

237
00:09:40,700 --> 00:09:43,640
save that back in our game.

238
00:09:43,640 --> 00:09:47,680
And there we go and run the game.

239
00:09:47,675 --> 00:09:50,465
So now we step in here,

240
00:09:50,465 --> 00:09:52,845
we get damaged, we step outside.

241
00:09:52,849 --> 00:09:53,479
There we go.

242
00:09:53,480 --> 00:09:55,190
We can see that the animation stops,

243
00:09:55,190 --> 00:09:58,060
but there is something when I stop and go back,

244
00:09:58,055 --> 00:10:01,495
you can see that even though I'm outside, so step back.

245
00:10:01,490 --> 00:10:03,530
I am still getting damaged.

246
00:10:03,530 --> 00:10:06,590
Why? Because the animation in here is still playing.

247
00:10:06,590 --> 00:10:08,570
Events system is still getting

248
00:10:08,570 --> 00:10:11,380
triggered and we do know what the player is.

249
00:10:11,375 --> 00:10:12,815
So to avoid that,

250
00:10:12,815 --> 00:10:17,045
I'm going to create a public bool.

251
00:10:17,045 --> 00:10:19,135
And this public bool just so we can see it in

252
00:10:19,130 --> 00:10:21,940
the inspector will later on set it to private.

253
00:10:21,935 --> 00:10:23,215
And I'm going to call this

254
00:10:23,210 --> 00:10:30,700
the give player or damage player,

255
00:10:30,695 --> 00:10:32,215
or shouldn't damage player,

256
00:10:32,210 --> 00:10:34,040
I believe is a better name for this.

257
00:10:34,040 --> 00:10:37,490
Verbs should damage player.

258
00:10:37,490 --> 00:10:39,840
And once he is inside,

259
00:10:39,844 --> 00:10:43,464
then the should damage player is equal to true.

260
00:10:43,460 --> 00:10:48,840
When he's outside the should damage player is false.

261
00:10:48,840 --> 00:10:52,240
And then inside of the damage player method,

262
00:10:52,240 --> 00:10:56,010
I'm going to check if we should manage the player.

263
00:10:56,005 --> 00:10:58,905
Then we are going to go ahead and

264
00:10:58,900 --> 00:11:01,990
access the player health handler and damage the player.

265
00:11:01,990 --> 00:11:04,710
So now back in our game,

266
00:11:04,705 --> 00:11:07,575
we should see that when I run the game,

267
00:11:07,570 --> 00:11:09,700
we should not damage the player.

268
00:11:09,700 --> 00:11:11,080
Once I step in here, we should

269
00:11:11,080 --> 00:11:13,200
damage the player, we get damaged.

270
00:11:13,195 --> 00:11:17,175
But if I activated and then go outside, there you go.

271
00:11:17,170 --> 00:11:19,930
You can see that should damage player book, book.

272
00:11:19,930 --> 00:11:20,710
There we go.

273
00:11:20,710 --> 00:11:23,400
You can see that I am no longer affected.

274
00:11:23,395 --> 00:11:25,165
So I hope you enjoyed this video.

275
00:11:25,165 --> 00:11:27,205
I hope you enjoyed this section.

276
00:11:27,205 --> 00:11:29,835
I hope you are always staging your files,

277
00:11:29,830 --> 00:11:32,830
committing your changes, creating reviews.

278
00:11:32,825 --> 00:11:35,275
And then in the next section we will

279
00:11:35,270 --> 00:11:37,780
see where this journey takes us.

280
00:11:37,775 --> 00:11:40,105
So I'm going to go ahead and say in

281
00:11:40,100 --> 00:11:42,800
here that I created spikes,

282
00:11:42,800 --> 00:11:49,370
that damage layer, commit the changes.

283
00:11:49,370 --> 00:11:51,140
And I can see right here and

284
00:11:51,140 --> 00:11:54,610
the masters how our game is moving along.

285
00:11:54,605 --> 00:11:57,235
Look how much we did,

286
00:11:57,230 --> 00:11:59,990
and look how much we still have to do.

287
00:11:59,990 --> 00:12:03,320
This game is just getting started so I can not wait.

288
00:12:03,320 --> 00:12:05,270
Let's not waste any more time and I'll see

289
00:12:05,270 --> 00:12:08,190
you in the next video.

