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

2
00:00:03,224 --> 00:00:05,374
In this video, we not only

3
00:00:05,370 --> 00:00:08,240
have this bar sitting here looking pretty,

4
00:00:08,235 --> 00:00:09,875
when we get hit,

5
00:00:09,870 --> 00:00:12,360
you'll see that our health goes down.

6
00:00:12,360 --> 00:00:14,160
So now when we get hit another time,

7
00:00:14,160 --> 00:00:15,890
There we go, you can see that we die.

8
00:00:15,885 --> 00:00:18,155
Obviously there is this little problem that

9
00:00:18,150 --> 00:00:20,690
we will talk about not addressed right now,

10
00:00:20,685 --> 00:00:23,645
but we will talk about it later on.

11
00:00:23,640 --> 00:00:26,220
So without any further or do a let's not

12
00:00:26,220 --> 00:00:29,670
waste any more time and let's get started.

13
00:00:29,665 --> 00:00:33,965
Okay, so now we have a slider,

14
00:00:33,965 --> 00:00:35,435
we have the text.

15
00:00:35,435 --> 00:00:37,915
All of these represent the health of the player,

16
00:00:37,910 --> 00:00:40,160
but still, when we take damage,

17
00:00:40,160 --> 00:00:41,990
the health doesn't go down.

18
00:00:41,990 --> 00:00:45,230
So what we're going to do is we're going to be changing

19
00:00:45,230 --> 00:00:49,750
this behavior based on using the UI Manager.

20
00:00:49,745 --> 00:00:53,225
So let's go into the UI Manager and let's get

21
00:00:53,225 --> 00:00:55,585
a reference to both the health slider

22
00:00:55,580 --> 00:00:57,280
and the health text.

23
00:00:57,275 --> 00:00:59,495
Now these will be public.

24
00:00:59,495 --> 00:01:01,105
And why are they public?

25
00:01:01,100 --> 00:01:02,600
Well, because we will be

26
00:01:02,600 --> 00:01:04,610
handling them in a different script,

27
00:01:04,610 --> 00:01:06,920
which is the player's health handled.

28
00:01:06,920 --> 00:01:10,370
So I'm going to create a public Slider,

29
00:01:10,370 --> 00:01:13,360
and it's going to be the health Slider.

30
00:01:13,355 --> 00:01:15,475
And remember, we could not have used

31
00:01:15,470 --> 00:01:19,070
this slider if we did not have the Unity engine Ow.ly.

32
00:01:19,070 --> 00:01:21,800
So as you can see, I commented this out and you

33
00:01:21,800 --> 00:01:24,910
can see that the slider now it does not exist.

34
00:01:24,905 --> 00:01:26,615
So that's continue one,

35
00:01:26,615 --> 00:01:29,325
do we have now a reference to the health slider?

36
00:01:29,329 --> 00:01:31,399
Next, we need a reference to

37
00:01:31,400 --> 00:01:35,380
the text of the health vexed.

38
00:01:35,375 --> 00:01:38,225
And these are very basic.

39
00:01:38,225 --> 00:01:40,045
Now we're going to save this and

40
00:01:40,040 --> 00:01:42,160
remember we have an instance,

41
00:01:42,155 --> 00:01:44,485
a static instance in the awake.

42
00:01:44,480 --> 00:01:47,020
So I'm going to go into the player handler,

43
00:01:47,015 --> 00:01:49,595
health handler right here and then start.

44
00:01:49,595 --> 00:01:51,935
As soon as I said, the current health,

45
00:01:51,935 --> 00:01:56,515
I'm going to access the UI Manager dot instance,

46
00:01:56,510 --> 00:02:01,690
dot health slider dot the max value.

47
00:02:01,685 --> 00:02:04,895
And I'm going to set it as the max health.

48
00:02:04,895 --> 00:02:08,275
And then I'm going to do the same with the UI.

49
00:02:08,270 --> 00:02:10,200
Where is it UI Manager,

50
00:02:10,204 --> 00:02:14,814
the instance, health slider,

51
00:02:14,810 --> 00:02:17,480
and the current value,

52
00:02:17,480 --> 00:02:19,130
which is represented by value,

53
00:02:19,130 --> 00:02:21,740
will be the current health.

54
00:02:21,740 --> 00:02:25,550
There we go. So now when I run the game,

55
00:02:25,550 --> 00:02:28,400
if I go into the doom player and I'm going

56
00:02:28,400 --> 00:02:31,520
to set his max health for,

57
00:02:31,520 --> 00:02:33,680
let's say, Oh, okay,

58
00:02:33,680 --> 00:02:35,950
let's just set the current

59
00:02:35,945 --> 00:02:38,765
open because we are already setting here.

60
00:02:38,765 --> 00:02:41,555
I'm just going to comment this out for the reason of

61
00:02:41,555 --> 00:02:46,315
actually having different max value and current values.

62
00:02:46,310 --> 00:02:48,700
So I'm going to set this, let's say at 20.

63
00:02:48,695 --> 00:02:50,255
So when I run the game,

64
00:02:50,255 --> 00:02:52,105
we should see that this Health Bot

65
00:02:52,100 --> 00:02:54,160
will move. And it didn't.

66
00:02:54,155 --> 00:02:56,755
Because obviously, we can see right here

67
00:02:56,750 --> 00:02:59,050
the object reference not set and

68
00:02:59,045 --> 00:03:01,795
I'll know what the problem is if I double-click in here,

69
00:03:01,790 --> 00:03:04,940
we haven't said the health slider on the UI canvas.

70
00:03:04,940 --> 00:03:06,920
So back in the UI canvas,

71
00:03:06,920 --> 00:03:09,140
obviously we need to set this right here.

72
00:03:09,140 --> 00:03:11,990
So health and the slider,

73
00:03:11,990 --> 00:03:14,840
I'm going to drag the slider and the health flexed.

74
00:03:14,840 --> 00:03:17,360
There we go. Nope, not the text.

75
00:03:17,360 --> 00:03:18,860
Oh, okay, So this is

76
00:03:18,860 --> 00:03:21,100
something that we need to talk about.

77
00:03:21,095 --> 00:03:24,205
So the health facts here is not just any text,

78
00:03:24,200 --> 00:03:26,840
it's a text Mesh Pro,

79
00:03:26,840 --> 00:03:29,840
so we cannot be using, where is it?

80
00:03:29,840 --> 00:03:32,680
Where's the UI Manager? There we go.

81
00:03:32,675 --> 00:03:36,575
So I'm going to move it so we cannot just use the text.

82
00:03:36,575 --> 00:03:40,145
We need to have a text Mesh Pro,

83
00:03:40,145 --> 00:03:42,385
but you can see we don't have the text mesh.

84
00:03:42,380 --> 00:03:45,740
Why? Because before we can use the text Mesh Pro,

85
00:03:45,740 --> 00:03:48,350
we need to have the appropriate namespace.

86
00:03:48,350 --> 00:03:50,510
So using, Let's see,

87
00:03:50,510 --> 00:03:54,650
I believe it's the Unity engine dot txt mesh.

88
00:03:54,650 --> 00:03:58,060
So using the TMP,

89
00:03:58,055 --> 00:04:00,755
there we go, hex mesh Pro.

90
00:04:00,755 --> 00:04:03,745
And now in here we can use the text,

91
00:04:03,740 --> 00:04:06,430
text mesh per row.

92
00:04:06,425 --> 00:04:08,335
And there we go. We save that.

93
00:04:08,330 --> 00:04:10,060
Now back in our game.

94
00:04:10,055 --> 00:04:11,455
And unity, I mean,

95
00:04:11,450 --> 00:04:15,080
we can go ahead and drag the health.

96
00:04:15,080 --> 00:04:18,890
I mean, in the UI canvas we can drag the health down.

97
00:04:18,890 --> 00:04:20,580
What is the problem?

98
00:04:20,584 --> 00:04:23,304
I believe that instead of text Mesh Pro,

99
00:04:23,300 --> 00:04:27,670
this also should be text Mesh pro GUI.

100
00:04:27,665 --> 00:04:28,975
Let's try this again.

101
00:04:28,970 --> 00:04:32,250
Save that now back in our game.

102
00:04:32,250 --> 00:04:35,530
And today, now, I will leave that.

103
00:04:35,530 --> 00:04:36,870
Now, there we go.

104
00:04:36,865 --> 00:04:38,695
Finally, we can add,

105
00:04:38,695 --> 00:04:40,125
so we save that.

106
00:04:40,120 --> 00:04:41,860
We run the game and we should

107
00:04:41,860 --> 00:04:43,840
see that the health, yep, There we go.

108
00:04:43,840 --> 00:04:46,270
So we've set the current health to 20,

109
00:04:46,270 --> 00:04:48,150
V-max Health to 100.

110
00:04:48,145 --> 00:04:51,495
So you can see that it's about 1 fifth of the way.

111
00:04:51,490 --> 00:04:53,880
So we know that this is working.

112
00:04:53,875 --> 00:04:57,705
The next step is to have this be updated every

113
00:04:57,700 --> 00:05:02,020
single time we take a hit or we actually start the game.

114
00:05:02,020 --> 00:05:03,580
So I'm going to,

115
00:05:03,580 --> 00:05:06,330
and your challenge is to update the health UI.

116
00:05:06,325 --> 00:05:07,615
So first of all, create

117
00:05:07,615 --> 00:05:09,915
a method that updates the health UI.

118
00:05:09,910 --> 00:05:11,560
So we are talking about the book,

119
00:05:11,560 --> 00:05:14,310
both the slider and the

120
00:05:14,310 --> 00:05:16,130
Next, then you'll need to

121
00:05:16,130 --> 00:05:18,290
use it in the appropriate places.

122
00:05:18,290 --> 00:05:20,240
So you'll need to think of where can I

123
00:05:20,240 --> 00:05:22,880
use the update of the UI?

124
00:05:22,880 --> 00:05:25,090
Make sure you also access

125
00:05:25,085 --> 00:05:27,625
the text and the, and update it.

126
00:05:27,620 --> 00:05:29,540
And finally, I'll give you a hint of

127
00:05:29,540 --> 00:05:32,030
where you can be using this update UI.

128
00:05:32,030 --> 00:05:36,160
You can use it in the start and when the player gets hit.

129
00:05:36,155 --> 00:05:38,005
So with that out of the way,

130
00:05:38,000 --> 00:05:42,380
pause the video right now and go to the Sharon.

131
00:05:42,380 --> 00:05:44,690
Oh, okay, welcome back.

132
00:05:44,690 --> 00:05:48,560
So I'm going to go into the player health handler.

133
00:05:48,560 --> 00:05:50,470
And in here I'm going to create

134
00:05:50,465 --> 00:05:58,295
a private void, update layer health.

135
00:05:59,530 --> 00:06:03,350
And in here what we're going to do is first of all,

136
00:06:03,350 --> 00:06:07,460
we are going to access the UI Manager dot

137
00:06:07,460 --> 00:06:14,000
instance dot Health text, dot text.

138
00:06:14,000 --> 00:06:17,270
And we're going to set it to the current health.

139
00:06:17,270 --> 00:06:19,750
Then we are going to concatenate it.

140
00:06:19,745 --> 00:06:21,485
So I know you haven't done this yet,

141
00:06:21,485 --> 00:06:24,055
but this way we are concatenating.

142
00:06:24,050 --> 00:06:25,940
So first of all, we take the current health,

143
00:06:25,940 --> 00:06:28,130
we add this dash right here or not

144
00:06:28,130 --> 00:06:30,560
that forward slash, it's called, I believe.

145
00:06:30,560 --> 00:06:34,280
And we are going to set the max health and here also.

146
00:06:34,280 --> 00:06:36,160
So we're going to save that.

147
00:06:36,155 --> 00:06:37,795
But not only this,

148
00:06:37,790 --> 00:06:41,280
we are also going to change the value of the slider.

149
00:06:41,284 --> 00:06:43,404
So in here I'm also going to access

150
00:06:43,400 --> 00:06:49,810
the UI Manager dot instance dot health slider dot value.

151
00:06:49,805 --> 00:06:52,985
And it's going to be equal to the current.

152
00:06:52,985 --> 00:06:55,105
Oops, sorry for that.

153
00:06:55,100 --> 00:06:56,510
The current.

154
00:06:56,510 --> 00:06:59,710
So the current health, yeah, that was it.

155
00:06:59,705 --> 00:07:00,965
Save that.

156
00:07:00,965 --> 00:07:03,365
So now the question is,

157
00:07:03,365 --> 00:07:05,795
where do we actually use this?

158
00:07:05,795 --> 00:07:07,385
So there are two places.

159
00:07:07,385 --> 00:07:10,225
First of all, we can use it in the start and

160
00:07:10,220 --> 00:07:12,200
then we kind of

161
00:07:12,200 --> 00:07:13,700
already use it and the start

162
00:07:13,700 --> 00:07:15,160
because we said the current health,

163
00:07:15,155 --> 00:07:17,965
but we are going to remove this line and we are

164
00:07:17,960 --> 00:07:20,830
going to simply call the Update Player health.

165
00:07:20,825 --> 00:07:23,875
And then every time we take damage in here,

166
00:07:23,870 --> 00:07:25,790
after we remove the amount of damage,

167
00:07:25,790 --> 00:07:27,620
we are going to set this,

168
00:07:27,620 --> 00:07:30,760
but I believe it's much better to sell it

169
00:07:30,755 --> 00:07:35,545
after we check the health of 0, maybe not.

170
00:07:35,540 --> 00:07:37,850
The only thing here that I'm

171
00:07:37,850 --> 00:07:39,560
worried about is having the Health

172
00:07:39,560 --> 00:07:42,830
be negative and seeing the bar going the other way.

173
00:07:42,830 --> 00:07:45,850
That's the only thing that bothers me about this.

174
00:07:45,845 --> 00:07:49,525
So I'm going to go ahead and maybe set it in here.

175
00:07:49,520 --> 00:07:53,630
So after we check if we are less than 0,

176
00:07:53,630 --> 00:07:56,240
this may also not look very pretty.

177
00:07:56,240 --> 00:07:58,990
When we die, we still have a bit of health.

178
00:07:58,985 --> 00:08:01,355
Let's see, You know what?

179
00:08:01,355 --> 00:08:02,465
Let's put it in here.

180
00:08:02,465 --> 00:08:03,565
No worries about that.

181
00:08:03,560 --> 00:08:05,000
Later on we will make this

182
00:08:05,000 --> 00:08:07,270
small tweak it changes where we

183
00:08:07,265 --> 00:08:11,695
turn off also the bar whenever we deactivate the player.

184
00:08:11,690 --> 00:08:13,040
So with that done,

185
00:08:13,040 --> 00:08:15,460
save all of that back in our game.

186
00:08:15,455 --> 00:08:17,815
And I'm going to let c in here.

187
00:08:17,810 --> 00:08:19,070
Let's remove this comment,

188
00:08:19,070 --> 00:08:25,100
save that because we actually now have proper health.

189
00:08:25,100 --> 00:08:29,830
I'm going to go into the dome player and let's see.

190
00:08:29,825 --> 00:08:31,285
Let's remove the current health.

191
00:08:31,280 --> 00:08:32,480
This is just to keep track,

192
00:08:32,480 --> 00:08:34,870
we will make sure that it's private later on.

193
00:08:34,865 --> 00:08:36,985
And what did I want to do?

194
00:08:36,980 --> 00:08:39,380
Because the weapon that the enemy is

195
00:08:39,380 --> 00:08:42,160
throwing at us deals and 50 damage, I believe.

196
00:08:42,155 --> 00:08:45,325
So let's make this 300.

197
00:08:45,320 --> 00:08:48,140
So the max health of the player is 300.

198
00:08:48,140 --> 00:08:49,880
I run the game.

199
00:08:49,880 --> 00:08:52,040
And we should see that the max health,

200
00:08:52,040 --> 00:08:54,440
you can see that we have 300 out of 300.

201
00:08:54,440 --> 00:08:56,480
So I'm going to come close to the enemy.

202
00:08:56,480 --> 00:08:57,940
He says, There we go.

203
00:08:57,935 --> 00:09:01,225
You can see that the health is slowly going down.

204
00:09:01,220 --> 00:09:03,640
And finally the last one, we die.

205
00:09:03,635 --> 00:09:06,445
But you'll notice there is a small error that

206
00:09:06,440 --> 00:09:10,130
appeared and it is coming at us a lot.

207
00:09:10,130 --> 00:09:12,120
So I'm going to stop the game.

208
00:09:12,120 --> 00:09:15,940
I'm going to so now we have to consult when those we

209
00:09:15,940 --> 00:09:17,230
don't want that close one of

210
00:09:17,230 --> 00:09:19,480
them and you can see that there is a problem.

211
00:09:19,480 --> 00:09:21,360
And what is the problem?

212
00:09:21,355 --> 00:09:23,725
First of all, we have the enemy bullet controller

213
00:09:23,725 --> 00:09:25,365
can't find the player.

214
00:09:25,360 --> 00:09:28,350
Second of all, we have, I believe.

215
00:09:28,345 --> 00:09:30,715
Okay, So no, not the problem in here.

216
00:09:30,715 --> 00:09:33,615
Well, the problem is actually that we are still trying to

217
00:09:33,610 --> 00:09:36,510
get a reference of the player even though he's dead.

218
00:09:36,505 --> 00:09:39,015
So we're trying to change the health slide.

219
00:09:39,010 --> 00:09:41,920
But anyways, these are small tweaks that we are

220
00:09:41,920 --> 00:09:45,120
obviously going to later on take care of.

221
00:09:45,115 --> 00:09:46,885
But for now I hope you enjoy it.

222
00:09:46,885 --> 00:09:51,195
I hope you now understand and feel how nice our game is.

223
00:09:51,190 --> 00:09:53,140
So everything is done dynamically.

224
00:09:53,140 --> 00:09:55,670
Everything changes automatically using

225
00:09:55,670 --> 00:09:59,000
the code and our game is really taking shape.

226
00:09:59,000 --> 00:10:00,560
So I hope you enjoy it and I'll

227
00:10:00,560 --> 00:10:02,330
see you in the next video.

228
00:10:02,330 --> 00:10:06,060
Don't forget to of course, commit your changes.

