1
00:00:00,000 --> 00:00:03,090
Welcome back, my fellow game developers.

2
00:00:03,090 --> 00:00:05,730
In this video, when you can see right here that we have

3
00:00:05,730 --> 00:00:08,670
these green health pickups.

4
00:00:08,670 --> 00:00:09,840
So when we get hit,

5
00:00:09,840 --> 00:00:13,200
you notice that we are live as 500 over 600.

6
00:00:13,200 --> 00:00:15,000
But once I pick up these health,

7
00:00:15,000 --> 00:00:18,210
you'll notice that I increase my health and

8
00:00:18,210 --> 00:00:21,440
now we're back in business and we can shoot everybody up.

9
00:00:21,435 --> 00:00:23,075
So without further ado,

10
00:00:23,070 --> 00:00:24,500
let's not waste any more time.

11
00:00:24,495 --> 00:00:27,305
I do make a couple of mistakes in this video.

12
00:00:27,300 --> 00:00:29,490
I hope you'll enjoy the lesson from

13
00:00:29,490 --> 00:00:32,270
them and let's not waste any more time again.

14
00:00:32,265 --> 00:00:34,495
And let's get started.

15
00:00:34,495 --> 00:00:38,695
Oh, okay, so let's add the ability for

16
00:00:38,690 --> 00:00:42,660
the player to pick up some health while he is damaged.

17
00:00:42,664 --> 00:00:44,874
So the first thing I want to do is I

18
00:00:44,870 --> 00:00:47,660
want to create the prefab out of the spike trap.

19
00:00:47,660 --> 00:00:51,920
So prefab and what should be having here.

20
00:00:51,920 --> 00:00:53,600
Let's right-click in here and

21
00:00:53,600 --> 00:00:56,660
create a folder for the level objects.

22
00:00:56,660 --> 00:01:01,570
So level objects.

23
00:01:01,565 --> 00:01:05,105
And let's go ahead and add the spike trap and here,

24
00:01:05,105 --> 00:01:06,665
and let's just keep it in our world.

25
00:01:06,665 --> 00:01:08,575
Now, the next thing we want to do is to

26
00:01:08,570 --> 00:01:11,350
go into the sprites.

27
00:01:11,345 --> 00:01:13,375
Where are the sprites?

28
00:01:13,370 --> 00:01:15,970
And let's say that in here we have

29
00:01:15,965 --> 00:01:18,925
the health pickup or you know what,

30
00:01:18,920 --> 00:01:23,030
let's just call them the PEC Ops. Hit Enter.

31
00:01:23,030 --> 00:01:26,330
And in here I'm going to go into the resources and drag

32
00:01:26,330 --> 00:01:29,990
the entire PNG or image or whatever you wanna call it.

33
00:01:29,990 --> 00:01:32,560
And I wanted to do this outside

34
00:01:32,555 --> 00:01:35,335
and do it before we start the video.

35
00:01:35,330 --> 00:01:37,850
But I thought that maybe some of you might have been

36
00:01:37,850 --> 00:01:40,780
angry that I created all the animations and stuff.

37
00:01:40,775 --> 00:01:43,775
So I thought that let's create them together.

38
00:01:43,775 --> 00:01:45,355
If you want, we can go ahead

39
00:01:45,350 --> 00:01:47,080
and see who can do it faster.

40
00:01:47,075 --> 00:01:50,155
So 64 by 64 or less slides that, okay,

41
00:01:50,150 --> 00:01:51,470
obviously it should be

42
00:01:51,470 --> 00:01:57,770
32 by 32 slice that applied changes. There we go.

43
00:01:57,770 --> 00:01:59,870
Now I'm going to get one of those,

44
00:01:59,870 --> 00:02:02,110
add them to the world in here.

45
00:02:02,105 --> 00:02:03,265
It's extremely small.

46
00:02:03,260 --> 00:02:05,590
Let's set it on the layer, layer.

47
00:02:05,585 --> 00:02:07,165
It's still extremely small.

48
00:02:07,160 --> 00:02:09,830
Let's make it 32 and the pixels per

49
00:02:09,830 --> 00:02:14,680
unit apply the changes so it's a bit still a bit small.

50
00:02:14,675 --> 00:02:17,465
Let's make it maybe 16.

51
00:02:17,465 --> 00:02:19,465
Apply the changes. There we go.

52
00:02:19,460 --> 00:02:20,630
I think this is good.

53
00:02:20,630 --> 00:02:23,510
And by the way, this is one of the ugliest health pickups

54
00:02:23,510 --> 00:02:26,480
that I've ever that I've ever seen.

55
00:02:26,480 --> 00:02:28,240
So if you want now, no,

56
00:02:28,235 --> 00:02:29,785
I didn't want to say that because

57
00:02:29,780 --> 00:02:31,460
maybe the person that worked on

58
00:02:31,460 --> 00:02:34,130
them maybe had a tough time

59
00:02:34,130 --> 00:02:35,690
creating the shadows and so on.

60
00:02:35,690 --> 00:02:36,950
So I'm sorry for saying that,

61
00:02:36,950 --> 00:02:38,960
but honestly, they're not that good.

62
00:02:38,960 --> 00:02:42,020
So I do recommend that you go find your own sprites.

63
00:02:42,020 --> 00:02:44,060
All I want to do is make sure that we

64
00:02:44,060 --> 00:02:46,100
have the game mechanics and place.

65
00:02:46,100 --> 00:02:48,370
It doesn't have to be extremely pretty.

66
00:02:48,365 --> 00:02:51,355
Anyways, we add a box collider obviously.

67
00:02:51,350 --> 00:02:52,900
Let's see how big that is.

68
00:02:52,895 --> 00:02:54,925
Yep, I think that is big enough.

69
00:02:54,920 --> 00:02:57,530
We'll make sure it's a trigger will save that.

70
00:02:57,530 --> 00:03:01,030
We'll go into the scripts in here

71
00:03:01,025 --> 00:03:04,675
and let's right-click and create a C-sharp script

72
00:03:04,670 --> 00:03:12,290
for the health or the health pickup. Hit enter.

73
00:03:12,290 --> 00:03:16,250
And we'll create a folder which will be the pickups.

74
00:03:16,250 --> 00:03:17,860
So any day now,

75
00:03:17,855 --> 00:03:21,605
pickups and add the health pickup and do the pickups.

76
00:03:21,605 --> 00:03:23,545
And then we'll add the health pickup

77
00:03:23,540 --> 00:03:25,390
into the health pickup.

78
00:03:25,385 --> 00:03:26,875
How cool is that?

79
00:03:26,870 --> 00:03:29,750
So health pickup gets a new component,

80
00:03:29,749 --> 00:03:32,679
which is the health pickup script.

81
00:03:32,675 --> 00:03:34,285
There we go, open it up in

82
00:03:34,280 --> 00:03:36,140
Visual Studio and let's get started.

83
00:03:36,140 --> 00:03:38,480
So what do we need in here?

84
00:03:38,480 --> 00:03:40,190
First of all, obviously we need to

85
00:03:40,190 --> 00:03:42,380
know the amount that this will heal.

86
00:03:42,380 --> 00:03:45,500
So serialized field, we'll make it an

87
00:03:45,500 --> 00:03:49,700
integer and we'll call this the heel amount endless.

88
00:03:49,700 --> 00:03:52,370
Just set it to be, I don't know, like maybe ten.

89
00:03:52,370 --> 00:03:55,090
I think ten is a good enough number.

90
00:03:55,085 --> 00:03:58,015
I'm going to remove the start and update for now.

91
00:03:58,010 --> 00:04:01,160
And I'm going to go ahead and create an on

92
00:04:01,160 --> 00:04:03,590
Trigger Enter to the

93
00:04:03,590 --> 00:04:07,330
obviously what are we looking for? Compare tag.

94
00:04:07,325 --> 00:04:09,175
I mean, sorry, we need

95
00:04:09,170 --> 00:04:11,000
to first of all get the collision and

96
00:04:11,000 --> 00:04:14,690
then we compare the tag and that tag as the player.

97
00:04:14,690 --> 00:04:16,780
So you've already seen all of this,

98
00:04:16,775 --> 00:04:18,955
I think about 1000 times, but anyways,

99
00:04:18,950 --> 00:04:21,500
this is what we should be going through.

100
00:04:21,500 --> 00:04:22,910
But before I do that,

101
00:04:22,910 --> 00:04:25,690
let me just create the animation for the health pickup.

102
00:04:25,685 --> 00:04:30,155
So Animation, create animation.

103
00:04:30,155 --> 00:04:32,395
Let's create a folder in here which is going

104
00:04:32,390 --> 00:04:35,390
to be the pickups.

105
00:04:35,390 --> 00:04:37,520
Maybe we do add a bit of more pickups.

106
00:04:37,520 --> 00:04:38,690
And in here we'll create

107
00:04:38,690 --> 00:04:43,370
the health pickup just

108
00:04:43,370 --> 00:04:45,020
to make sure that everything is really

109
00:04:45,020 --> 00:04:47,260
clean and easy to go through.

110
00:04:47,255 --> 00:04:54,445
So now we get the health up, down, up, down.

111
00:04:54,440 --> 00:04:59,450
That go to the sprite switches on.

112
00:04:59,450 --> 00:05:02,980
And where is it?

113
00:05:02,975 --> 00:05:05,735
Backup, health pickup.

114
00:05:05,735 --> 00:05:06,715
There we go.

115
00:05:06,710 --> 00:05:08,500
Let's add all of these images

116
00:05:08,495 --> 00:05:11,105
and we'll keep it as the default layer that's run.

117
00:05:11,105 --> 00:05:14,845
Okay, that's an extremely fast, maybe like that.

118
00:05:14,840 --> 00:05:17,450
Nope, that is boring.

119
00:05:17,450 --> 00:05:19,450
Like that.

120
00:05:19,445 --> 00:05:23,845
Okay. I think that is good enough maybe.

121
00:05:23,840 --> 00:05:26,060
Yeah, sure. Why not? So let's just keep

122
00:05:26,060 --> 00:05:29,040
it at that. I think.

123
00:05:29,044 --> 00:05:30,534
Yeah, Sure.

124
00:05:30,530 --> 00:05:32,510
As long as we can see what's happening

125
00:05:32,510 --> 00:05:34,640
and it's just moving a little bit.

126
00:05:34,640 --> 00:05:36,830
Maybe make it a bit slower.

127
00:05:36,830 --> 00:05:39,040
Nope, that's 2 first.

128
00:05:39,035 --> 00:05:40,045
I don't know.

129
00:05:40,040 --> 00:05:41,360
This will really depend on you.

130
00:05:41,360 --> 00:05:43,070
How do you want your pickup to look?

131
00:05:43,070 --> 00:05:45,500
Obviously, some of you have battery sprites,

132
00:05:45,500 --> 00:05:47,000
have better understanding of what

133
00:05:47,000 --> 00:05:48,860
makes an animation pretty.

134
00:05:48,860 --> 00:05:50,990
So I'll keep that to you as long as

135
00:05:50,990 --> 00:05:53,350
we have the health pickup working properly.

136
00:05:53,345 --> 00:05:54,745
Now let's go back in here.

137
00:05:54,740 --> 00:05:56,300
And what do we want to do in here

138
00:05:56,300 --> 00:05:58,240
after the player collides will

139
00:05:58,235 --> 00:06:01,795
obviously we want to increase the health of the player,

140
00:06:01,790 --> 00:06:03,710
but there is something

141
00:06:03,710 --> 00:06:05,510
that is not quite right and that is,

142
00:06:05,510 --> 00:06:07,550
we don't have any way of doing that.

143
00:06:07,550 --> 00:06:09,430
So I'm going to issue you

144
00:06:09,425 --> 00:06:12,545
a challenge to create a method that adds health.

145
00:06:12,545 --> 00:06:13,865
So first of all,

146
00:06:13,865 --> 00:06:16,075
and the player health handler create

147
00:06:16,070 --> 00:06:19,100
a method that adds health to the player.

148
00:06:19,100 --> 00:06:22,570
It should take a parameter which is the heel amount.

149
00:06:22,565 --> 00:06:25,085
You'll need to make sure that it never goes

150
00:06:25,085 --> 00:06:28,105
over the maximum of health that we have.

151
00:06:28,100 --> 00:06:30,140
So our maximum is 100.

152
00:06:30,140 --> 00:06:32,960
We don't want to have 120, for example.

153
00:06:32,960 --> 00:06:35,030
And finally, and most importantly,

154
00:06:35,030 --> 00:06:38,360
you need to make sure to also update the UI canvas.

155
00:06:38,360 --> 00:06:40,060
So with that information,

156
00:06:40,055 --> 00:06:45,115
pause the video right now and go do reach challenge.

157
00:06:45,110 --> 00:06:47,060
Gay. Welcome back.

158
00:06:47,060 --> 00:06:48,760
How did you get on that?

159
00:06:48,755 --> 00:06:50,395
I hope it wasn't too hard

160
00:06:50,390 --> 00:06:52,310
and I hope you gave it your all.

161
00:06:52,310 --> 00:06:56,330
So in here where we damage the player right under,

162
00:06:56,330 --> 00:06:59,130
we are going to create a public void.

163
00:06:59,130 --> 00:07:03,440
And it's going to be add HB two player.

164
00:07:03,440 --> 00:07:07,040
And it's going to take in an integer parameter,

165
00:07:07,040 --> 00:07:10,990
which is the heel amount.

166
00:07:10,985 --> 00:07:13,555
And what shall we be doing in here?

167
00:07:13,550 --> 00:07:16,600
Well, we are going to be accessing the current health

168
00:07:16,595 --> 00:07:18,625
and we are going to be increasing

169
00:07:18,620 --> 00:07:20,780
it by the health amount.

170
00:07:20,780 --> 00:07:22,840
Now for the tricky part,

171
00:07:22,835 --> 00:07:25,535
if we have the current health

172
00:07:25,535 --> 00:07:28,025
greater than the max health,

173
00:07:28,025 --> 00:07:29,525
what should we be doing?

174
00:07:29,525 --> 00:07:30,655
Well, we should be setting

175
00:07:30,650 --> 00:07:34,180
the current health to be equal to the max health.

176
00:07:34,175 --> 00:07:36,355
So this will ensure that the current health

177
00:07:36,350 --> 00:07:39,050
never goes over the max health.

178
00:07:39,050 --> 00:07:40,480
And finally, we need to

179
00:07:40,475 --> 00:07:44,905
update player Health Plan, Update Player health.

180
00:07:44,900 --> 00:07:47,380
Yep, Update Player health. You know what?

181
00:07:47,375 --> 00:07:49,535
Double-click in here, Control RR,

182
00:07:49,535 --> 00:07:52,055
Update Player health you are.

183
00:07:52,055 --> 00:07:54,965
And the problem is

184
00:07:54,965 --> 00:07:59,095
that there is something, one unresolved conflict.

185
00:07:59,090 --> 00:08:00,890
What is the problem? Oh, okay.

186
00:08:00,890 --> 00:08:04,460
So in here, it doesn't know what it should be using.

187
00:08:04,460 --> 00:08:05,560
And there we go.

188
00:08:05,555 --> 00:08:08,545
So now we update the player health you are.

189
00:08:08,540 --> 00:08:11,680
And the last step is obviously to inhere,

190
00:08:11,675 --> 00:08:17,645
we are going to go to the collision, the Get component,

191
00:08:17,645 --> 00:08:19,555
because we already know this is the player,

192
00:08:19,550 --> 00:08:27,230
so we won't face any errors that what was called at,

193
00:08:27,230 --> 00:08:28,970
at HP to player,

194
00:08:28,970 --> 00:08:30,710
at HP to player.

195
00:08:30,710 --> 00:08:34,760
And we sent him the heel amount of this object.

196
00:08:34,760 --> 00:08:37,060
And finally, and of course we need to

197
00:08:37,055 --> 00:08:40,675
destroy the game object.

198
00:08:40,670 --> 00:08:43,250
There we go. I believe this is all that we

199
00:08:43,250 --> 00:08:45,530
need to do and this should be working.

200
00:08:45,530 --> 00:08:49,540
So back in our game, Let's run this.

201
00:08:49,535 --> 00:08:51,595
And let's see if that worked.

202
00:08:51,590 --> 00:08:53,420
So we are going to stand on the spikes,

203
00:08:53,420 --> 00:08:56,630
get hit once, Come on, Get him twice.

204
00:08:56,630 --> 00:08:57,580
There we go.

205
00:08:57,575 --> 00:08:59,965
Get hit a third time. Okay.

206
00:08:59,960 --> 00:09:02,090
So now our health is 300.

207
00:09:02,089 --> 00:09:03,829
So now when we pick up this,

208
00:09:03,830 --> 00:09:05,960
we should have 310.

209
00:09:05,955 --> 00:09:08,175
We have 320.

210
00:09:08,170 --> 00:09:10,140
So why do you think that happened?

211
00:09:10,135 --> 00:09:12,475
Let's see what the problem is here.

212
00:09:12,475 --> 00:09:17,625
So the health pickup has done, it hasn't animation.

213
00:09:17,620 --> 00:09:19,720
It has a box collider,

214
00:09:19,720 --> 00:09:23,710
but the problem, Oh, welcome back.

215
00:09:23,710 --> 00:09:27,130
So I believe it took me just a fraction of a

216
00:09:27,130 --> 00:09:28,540
second to know what happened

217
00:09:28,540 --> 00:09:30,610
because of the magic of editing.

218
00:09:30,610 --> 00:09:32,740
But I went through a couple of things.

219
00:09:32,740 --> 00:09:36,660
Just understand if my theory was correct and it was.

220
00:09:36,655 --> 00:09:39,085
So what I was thinking is that

221
00:09:39,085 --> 00:09:41,455
we have two colliders in here.

222
00:09:41,455 --> 00:09:44,035
We have the capsule collider of the player,

223
00:09:44,035 --> 00:09:46,845
and we have the Box Glider of the Player.

224
00:09:46,840 --> 00:09:48,560
One of them is 2.

225
00:09:48,555 --> 00:09:51,125
Make sure that we do not go beyond walls.

226
00:09:51,125 --> 00:09:54,055
So we made one that is small so we can have

227
00:09:54,050 --> 00:09:57,530
the illusion that this game is more than just a two.

228
00:09:57,530 --> 00:09:59,720
These are the wall doesn't actually make

229
00:09:59,720 --> 00:10:02,420
us unable to walk through it a little bit.

230
00:10:02,420 --> 00:10:05,120
So if you know what I mean, I'm in here.

231
00:10:05,120 --> 00:10:07,610
And then the second one is actually to be

232
00:10:07,610 --> 00:10:09,890
able to get shot from the hat.

233
00:10:09,890 --> 00:10:12,280
So the problem, What's happening?

234
00:10:12,275 --> 00:10:13,745
I'm trying to show you,

235
00:10:13,745 --> 00:10:16,045
I'm going to get hit by these spikes.

236
00:10:16,040 --> 00:10:19,580
And now if I walk with these two colliders,

237
00:10:19,580 --> 00:10:23,140
you'll notice that when I get to choose one of them,

238
00:10:23,135 --> 00:10:24,985
you see that I get 20 because I'm

239
00:10:24,980 --> 00:10:26,930
picking it up with both gliders.

240
00:10:26,930 --> 00:10:29,480
If I just pick it up with the collider above,

241
00:10:29,480 --> 00:10:34,130
look at the 520, you'll see that it's just 530.

242
00:10:34,130 --> 00:10:37,550
If I pick it up with my head only, I get 540.

243
00:10:37,550 --> 00:10:38,840
So 10, which is good.

244
00:10:38,840 --> 00:10:42,410
And if I pick it up on from the side, there you go.

245
00:10:42,410 --> 00:10:44,060
You can see that it added 20.

246
00:10:44,060 --> 00:10:46,510
So this is the problem that we need to fix.

247
00:10:46,505 --> 00:10:49,435
Now, I want you to take a moment and

248
00:10:49,430 --> 00:10:52,570
think of a solution to this problem.

249
00:10:52,565 --> 00:10:54,215
So I'm just going to give you,

250
00:10:54,215 --> 00:10:56,335
this is not a challenge, not an efficient challenge.

251
00:10:56,330 --> 00:10:59,280
I'm just going to give you a bit of time.

252
00:10:59,760 --> 00:11:02,260
Okay, time's up. So let's

253
00:11:02,260 --> 00:11:04,480
see what we are going to do in here.

254
00:11:04,480 --> 00:11:07,530
So the whole thing that we need to make sure of is that

255
00:11:07,525 --> 00:11:11,145
this health pickup has been picked up at least once.

256
00:11:11,140 --> 00:11:13,500
So what we'll do is we'll create

257
00:11:13,495 --> 00:11:20,155
a private bool and this is going to be called Pick it up.

258
00:11:20,155 --> 00:11:22,455
So it has been picked up.

259
00:11:22,450 --> 00:11:24,910
And in here we're going to say that if it's

260
00:11:24,910 --> 00:11:27,930
the player and it has not been picked up,

261
00:11:27,925 --> 00:11:29,845
so we add the exclamation mark,

262
00:11:29,845 --> 00:11:31,455
then we are going to pick up,

263
00:11:31,450 --> 00:11:35,020
but we'll also set this pickup to be true.

264
00:11:35,020 --> 00:11:37,770
So once we pick it up, once,

265
00:11:37,765 --> 00:11:40,875
That's it, We can no longer pick it up another time.

266
00:11:40,875 --> 00:11:42,235
So let's save that.

267
00:11:42,230 --> 00:11:45,080
Let's go back into our game and let's test this out.

268
00:11:45,080 --> 00:11:46,880
So we run the game,

269
00:11:46,880 --> 00:11:48,980
we get hit by the spikes.

270
00:11:48,980 --> 00:11:51,760
And then when we walk on the sides,

271
00:11:51,755 --> 00:11:53,315
there we go, we get 10.

272
00:11:53,315 --> 00:11:55,525
So no matter how much we try right now,

273
00:11:55,520 --> 00:11:58,610
we should never get this increasing by 20.

274
00:11:58,610 --> 00:12:01,540
So now I walk through this that you go on the sides,

275
00:12:01,535 --> 00:12:06,085
we always get 10 and never get an extra 20 or so.

276
00:12:06,080 --> 00:12:08,530
I hope you enjoy it. I hope you'd like this.

277
00:12:08,525 --> 00:12:12,175
And I really wasn't sure what the problem was solved.

278
00:12:12,170 --> 00:12:14,180
Took me maybe about two to three minutes,

279
00:12:14,180 --> 00:12:15,920
but I remember when I first

280
00:12:15,920 --> 00:12:18,340
started this took me maybe back.

281
00:12:18,335 --> 00:12:21,065
Today's to figure out what the hell was

282
00:12:21,065 --> 00:12:24,235
wrong with this games or why wasn't big begin picked up?

283
00:12:24,230 --> 00:12:25,720
This was a long time ago.

284
00:12:25,715 --> 00:12:27,385
Now, because of my experience,

285
00:12:27,380 --> 00:12:28,820
I understand things a bit

286
00:12:28,820 --> 00:12:31,280
quicker and this is what I want you to know that

287
00:12:31,280 --> 00:12:36,380
sometimes even though I know I have so much experience,

288
00:12:36,380 --> 00:12:37,540
I'm teaching you the scores.

289
00:12:37,535 --> 00:12:40,045
I also make a lot of mistakes and

290
00:12:40,040 --> 00:12:43,120
things happened that I have no clue why,

291
00:12:43,115 --> 00:12:45,505
even though this course actually I've

292
00:12:45,500 --> 00:12:48,580
created this game beforehand and went through everything.

293
00:12:48,575 --> 00:12:50,815
But I encountered this problem,

294
00:12:50,810 --> 00:12:51,980
so I hope you enjoy it.

295
00:12:51,980 --> 00:12:54,220
I hope you like my transparency that I

296
00:12:54,215 --> 00:12:57,065
always make sure to show you the mistakes I made,

297
00:12:57,065 --> 00:12:59,395
even though some people don't like it,

298
00:12:59,390 --> 00:13:02,710
they say that, how can an unstructured make mistakes?

299
00:13:02,705 --> 00:13:05,345
Oh no, everybody tries to be perfect.

300
00:13:05,345 --> 00:13:06,635
I know nobody is.

301
00:13:06,635 --> 00:13:07,415
Trust me.

302
00:13:07,415 --> 00:13:10,895
Everybody uses Google to figure out what the problem was.

303
00:13:10,895 --> 00:13:12,805
And this case I didn't because I've

304
00:13:12,800 --> 00:13:14,900
already encountered it and fixed it beforehand,

305
00:13:14,900 --> 00:13:16,240
so I hope you enjoy it.

306
00:13:16,235 --> 00:13:17,915
Make sure to stage your files

307
00:13:17,915 --> 00:13:21,005
and I'll see you in the next video.

