Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:06,656 --> 00:00:12,800
Do the first thing you need to think about whenever you create a new game on
2
00:00:13,056 --> 00:00:18,944
About the jump into changing a gameobject with a script on his case we can I change the health bar with
3
00:00:19,200 --> 00:00:20,224
With a script
4
00:00:20,736 --> 00:00:22,528
First thing you need to think about it
5
00:00:22,784 --> 00:00:25,088
Who needs a reference to this
6
00:00:25,600 --> 00:00:26,880
Who's going to be changing this
7
00:00:27,392 --> 00:00:27,904
Well
8
00:00:28,160 --> 00:00:29,952
We had a reference to coins
9
00:00:30,464 --> 00:00:31,744
In the player script
10
00:00:32,512 --> 00:00:35,584
The new player script double click on their script
11
00:00:36,096 --> 00:00:38,144
But we get the coins text
12
00:00:38,656 --> 00:00:39,424
UI
13
00:00:39,936 --> 00:00:40,960
Referenced here
14
00:00:41,984 --> 00:00:46,336
So when I had a similar reference to the image component
15
00:00:47,104 --> 00:00:49,664
So we can do is just type public
16
00:00:50,432 --> 00:00:51,712
Image
17
00:00:52,480 --> 00:00:53,504
Elf bar
18
00:00:55,552 --> 00:00:58,624
And we can technical go into the start function here
19
00:00:59,136 --> 00:01:00,397
Type health bar
20
00:01:00,399 --> 00:01:02,747
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
21
00:01:02,748 --> 00:01:03,488
Equals game object
22
00:01:05,024 --> 00:01:09,120
Define what the name is the name is health bar with a space
23
00:01:11,168 --> 00:01:11,680
Dad
24
00:01:11,936 --> 00:01:12,704
Member
25
00:01:12,960 --> 00:01:14,240
Because it's an image
26
00:01:15,008 --> 00:01:16,032
Variable type
27
00:01:16,544 --> 00:01:18,080
Winner deals getcomponent
28
00:01:18,592 --> 00:01:21,408
Image again weird syntax year
29
00:01:21,920 --> 00:01:23,456
But now it's going to find
30
00:01:23,712 --> 00:01:25,504
Health bar game object
31
00:01:25,760 --> 00:01:26,784
And then get the
32
00:01:27,552 --> 00:01:29,344
Now we can actually adjust
33
00:01:29,600 --> 00:01:30,368
Health bar
34
00:01:31,648 --> 00:01:35,232
Another way of doing this is just to get rid of her entirely
35
00:01:35,488 --> 00:01:38,048
Because there's only one player in the game
36
00:01:38,304 --> 00:01:39,584
We just say hey player
37
00:01:39,840 --> 00:01:40,608
How far
38
00:01:41,888 --> 00:01:42,912
Is this
39
00:01:43,680 --> 00:01:45,472
Dragon on a without of the
40
00:01:47,008 --> 00:01:48,544
Now here's a thing
41
00:01:49,056 --> 00:01:50,592
Weekly dinner health bar
42
00:01:50,848 --> 00:01:53,664
What we just referenced was the image component
43
00:01:54,432 --> 00:01:55,968
Well the image component
44
00:01:56,224 --> 00:01:58,016
Doesn't actually have anything to do with whip
45
00:01:58,272 --> 00:02:00,832
So why are we getting the image component
46
00:02:01,088 --> 00:02:02,880
In that the rect transform
47
00:02:03,392 --> 00:02:06,976
The reason why is because you can actually access the recttransform
48
00:02:07,488 --> 00:02:10,048
Simply by having any other reference to a component
49
00:02:10,304 --> 00:02:13,376
Ethical thing about recttransform in transformed bellies
50
00:02:13,632 --> 00:02:15,936
So what we can do is actually just go like this
51
00:02:16,448 --> 00:02:22,592
Update you I'll say I don't know the update function here in the new player script in Russia's rights
52
00:02:22,848 --> 00:02:27,200
Code I just say what's your test here said health bar
53
00:02:28,480 --> 00:02:28,992
With
54
00:02:29,248 --> 00:02:29,760
2
55
00:02:30,528 --> 00:02:31,296
100
56
00:02:33,088 --> 00:02:38,464
The way that we do there is health bar that wrecked transferred is recttransform
57
00:02:38,720 --> 00:02:40,512
I know this is a little confusing
58
00:02:40,768 --> 00:02:42,560
But there is certain components
59
00:02:42,816 --> 00:02:45,376
That come out of the box with unity
60
00:02:45,632 --> 00:02:48,192
You can just reference whenever you want to
61
00:02:48,960 --> 00:02:50,496
So even though health bar
62
00:02:51,008 --> 00:02:54,336
Does an actually have a variable called recttransform
63
00:02:54,592 --> 00:02:58,944
What is means if we're just going hey find something called recttransform
64
00:02:59,456 --> 00:03:00,736
In that game are checked
65
00:03:01,504 --> 00:03:03,808
Now that we have the recttransform value
66
00:03:04,064 --> 00:03:05,600
We can actually just like that
67
00:03:06,112 --> 00:03:09,696
And it's not actually with your height or even size
68
00:03:10,208 --> 00:03:14,304
Kind of weird with red Transformers actually size Delta
69
00:03:15,328 --> 00:03:17,120
Then you going to say equals
70
00:03:17,376 --> 00:03:18,144
New
71
00:03:18,400 --> 00:03:19,168
Vector
72
00:03:19,680 --> 00:03:20,448
2
73
00:03:21,472 --> 00:03:24,544
Yeah I just said it to you 100 and then
74
00:03:25,056 --> 00:03:28,384
Whatever it's current y valuers or height
75
00:03:28,896 --> 00:03:34,016
So again health bar that recttransform
76
00:03:34,528 --> 00:03:36,320
And I just close down
77
00:03:36,576 --> 00:03:37,344
With a semicolon
78
00:03:38,112 --> 00:03:39,136
Richard set
79
00:03:39,904 --> 00:03:42,464
How far to 100 units wide
80
00:03:42,720 --> 00:03:46,048
So in theory it should end up looking like that
81
00:03:46,560 --> 00:03:48,352
The moment we collect a coin
82
00:03:48,608 --> 00:03:53,472
And this is just a test to see if work setting the width properly so it's a play and see if that happens
83
00:03:55,776 --> 00:03:56,544
Here we go
84
00:03:56,800 --> 00:04:00,896
Alright so now we know how to change the actual width of a bar
85
00:04:01,408 --> 00:04:03,712
We're getting write an equation
86
00:04:06,528 --> 00:04:08,064
So I know one thing
87
00:04:08,320 --> 00:04:11,136
I know we need an original size
88
00:04:11,392 --> 00:04:12,416
Brother health bar
89
00:04:13,184 --> 00:04:14,976
We don't know how big
90
00:04:15,232 --> 00:04:16,000
The bar is
91
00:04:16,512 --> 00:04:17,791
When we start the game
92
00:04:18,303 --> 00:04:24,447
Create a variable is going to be private because we're not really going to need to see it and the inspector and we definitely don't need a
93
00:04:24,703 --> 00:04:27,263
From any other script in the game
94
00:04:27,519 --> 00:04:30,591
Private private
95
00:04:30,847 --> 00:04:32,639
Vector2
96
00:04:33,663 --> 00:04:36,479
Health bar original size
97
00:04:38,783 --> 00:04:43,135
What's this by default we created the variable but by the fault it's just
98
00:04:43,391 --> 00:04:46,463
00009 why or
99
00:04:46,719 --> 00:04:49,535
0 in width and 0 in the height
100
00:04:50,047 --> 00:04:53,119
So we need to make sure that we find out what that original size is
101
00:04:53,887 --> 00:04:55,423
So what we're going to do is going to say
102
00:04:55,935 --> 00:05:01,311
Health bar or Ridge size = the health Bar number that's the image
103
00:05:01,823 --> 00:05:02,847
Variable APR
104
00:05:03,871 --> 00:05:07,455
Dart recttransform size Delta
105
00:05:07,967 --> 00:05:10,783
The health bar original size this variable
106
00:05:11,551 --> 00:05:12,575
Is matching
107
00:05:13,087 --> 00:05:16,927
Finding out with the size delta of the red Transformers
108
00:05:17,183 --> 00:05:21,535
So just so we can see it in the Inspector was just serializability quick
109
00:05:21,791 --> 00:05:24,095
Remove this after we know for sure
110
00:05:24,607 --> 00:05:26,911
How much is go ahead hip play and make sure
111
00:05:28,959 --> 00:05:31,775
We can see what the health bar orig sizes
112
00:05:32,287 --> 00:05:36,639
Ok so we're just updated because we put it in the start function so right when we started
113
00:05:36,895 --> 00:05:38,431
It matched the value
114
00:05:38,687 --> 00:05:42,271
816 in width and 29 in height
115
00:05:44,063 --> 00:05:45,855
Where is perfect it's magic
116
00:05:46,367 --> 00:05:48,927
Cinematic how small I make this
117
00:05:50,719 --> 00:05:53,023
Pronounce 263
118
00:05:54,047 --> 00:05:58,911
When we go to iPlayer on new player skript here when we got a new player script here by selecting player
119
00:05:59,167 --> 00:06:01,471
The nearest that is still 816
120
00:06:01,983 --> 00:06:06,079
That's because it's found the original value when we were in the start function
121
00:06:07,103 --> 00:06:09,151
Mama hit play at SoundAbout value
122
00:06:09,919 --> 00:06:10,943
But now
123
00:06:11,711 --> 00:06:16,319
It's still has their value so it's remembering what the original value was
124
00:06:16,831 --> 00:06:18,879
Now we can find out the proportion
125
00:06:19,391 --> 00:06:23,999
Based on its original size to right now it's almost maybe 30%
126
00:06:24,511 --> 00:06:25,279
Aboriginal
127
00:06:25,791 --> 00:06:27,583
The way that you calculate that
128
00:06:28,351 --> 00:06:34,495
Is simply buy some Division so have you learnt this in high school maybe you're learning this right now in high school or college
129
00:06:34,751 --> 00:06:39,615
Have you forgotten all about this stuff and that's definitely ok we're going to do a little bit of a refresher here
130
00:06:40,127 --> 00:06:43,455
So basically to find the proportion or the percentage
131
00:06:43,711 --> 00:06:45,247
Original value
132
00:06:45,759 --> 00:06:51,135
You just divide so if we write some pseudocode here we go health bar that recttransform
133
00:06:52,159 --> 00:06:53,951
That size Delta
134
00:06:55,743 --> 00:06:58,047
X /
135
00:06:58,303 --> 00:06:59,839
The original value
136
00:07:00,607 --> 00:07:02,911
What is that that's health bar
137
00:07:03,679 --> 00:07:04,447
Norwich
138
00:07:04,703 --> 00:07:05,727
Size
139
00:07:06,239 --> 00:07:07,263
X
140
00:07:11,871 --> 00:07:15,455
What's go ahead in just for a quick maths refresher
141
00:07:15,711 --> 00:07:16,991
ASDA Bangor sell
142
00:07:17,247 --> 00:07:18,527
Debug.log
143
00:07:18,783 --> 00:07:20,319
This actually
144
00:07:20,575 --> 00:07:21,855
Into the debug window
145
00:07:24,671 --> 00:07:27,743
Tell we can write a Little Liars train here
146
00:07:29,791 --> 00:07:32,607
Health bar percentage is
147
00:07:34,655 --> 00:07:36,703
Whenever this number is so it's
148
00:07:36,959 --> 00:07:37,983
Print
149
00:07:38,239 --> 00:07:38,751
With
150
00:07:39,775 --> 00:07:42,335
÷ the original with
151
00:07:42,591 --> 00:07:44,639
The Crown which is 100
152
00:07:45,151 --> 00:07:47,199
The original it was 100
153
00:07:47,967 --> 00:07:49,247
What are percentage
154
00:07:49,759 --> 00:07:55,391
Well this is gonna give us a decimal not a percentage but we can jump in unity and take a look at it play here
155
00:07:57,439 --> 00:07:58,463
Collect something
156
00:07:59,231 --> 00:08:03,583
Alright so looks like the health bar percentage is .12
157
00:08:03,839 --> 00:08:06,399
What does that mean that swell 12%
158
00:08:07,423 --> 00:08:11,263
Number with percentages you just need a x x 100
159
00:08:12,543 --> 00:08:14,591
And I should give us an accurate
160
00:08:16,383 --> 00:08:17,663
Percentage
161
00:08:18,175 --> 00:08:21,247
So currently it's 12% of its original value
162
00:08:21,759 --> 00:08:24,831
That's perfect so that's going to be using
163
00:08:25,087 --> 00:08:26,623
When scaling is health bar
164
00:08:27,647 --> 00:08:33,791
So now we have a general understanding of not only how to change the size or the width
165
00:08:34,303 --> 00:08:35,327
The health bar
166
00:08:36,095 --> 00:08:42,239
We also have a general understanding of how percentages work and how we can find out what the percentage of the health bar is
167
00:08:42,751 --> 00:08:45,311
I'm just going to go ahead and comment all this out for now
168
00:08:46,847 --> 00:08:49,919
To our going to do is actually just going to the collectible script
169
00:08:50,431 --> 00:08:53,503
And we need to start setting some conditions
170
00:08:54,015 --> 00:08:55,039
Michael Dunn appear
171
00:08:55,551 --> 00:08:57,855
Do certain things to various variables
172
00:08:58,111 --> 00:09:00,159
So I know that if it's a coin
173
00:09:00,415 --> 00:09:01,439
I want to add
174
00:09:01,695 --> 00:09:03,487
To the coins collected variable
175
00:09:04,767 --> 00:09:06,559
And I know that it is a health
176
00:09:07,583 --> 00:09:08,607
Item type
177
00:09:09,375 --> 00:09:10,399
I want to add
178
00:09:12,191 --> 00:09:15,775
To another line Sonu player health
179
00:09:16,031 --> 00:09:20,895
Classical or mine is equals what in this case it can be plus equals
180
00:09:21,151 --> 00:09:21,663
Ok
181
00:09:22,175 --> 00:09:22,687
Well
182
00:09:22,943 --> 00:09:25,759
We want to add to a coins in their health
183
00:09:26,015 --> 00:09:28,831
Or let's say a coin collectible type
184
00:09:29,087 --> 00:09:31,135
We actually need to make these conditions
185
00:09:31,903 --> 00:09:32,927
Turn down here
186
00:09:33,439 --> 00:09:39,327
Go ahead and comment out all of these conditions here that We Created earlier and we're just going to come in the mail
187
00:09:39,583 --> 00:09:41,631
Because we actually can just copy and paste them
188
00:09:42,143 --> 00:09:45,983
Copy all of this we don't really need it in our start function
189
00:09:46,239 --> 00:09:52,383
That was just for a tutorial now actually going to put it inside of the ontriggerenter so weird paste all
190
00:09:53,407 --> 00:09:56,479
And we have I'm a coin here
191
00:09:57,759 --> 00:10:02,124
Remove all this debug stuff don't need this anymore that was just for the tutorial now actually making
192
00:10:02,125 --> 00:10:04,434
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
193
00:10:04,927 --> 00:10:07,999
So this is if I'm a coin then we want to add
194
00:10:11,071 --> 00:10:12,351
Health
195
00:10:12,863 --> 00:10:14,399
Bad health
196
00:10:14,911 --> 00:10:18,495
NN regardless no matter who I am
197
00:10:18,751 --> 00:10:20,543
I still want to update the UI
198
00:10:21,055 --> 00:10:22,079
Just to get the
199
00:10:22,335 --> 00:10:25,919
Variables to match the actual UI elements
200
00:10:26,175 --> 00:10:28,223
And then just destroy the game object
201
00:10:28,479 --> 00:10:31,807
Destroy the coin or the health object
202
00:10:32,575 --> 00:10:34,111
Don't say that out
203
00:10:34,367 --> 00:10:37,695
And let's see hear back in the Unity
204
00:10:38,207 --> 00:10:42,303
So I know that I don't want to spend too much time creating graphics for health
205
00:10:42,559 --> 00:10:45,119
So she just take this coin here
206
00:10:46,655 --> 00:10:47,935
Call this
207
00:10:48,191 --> 00:10:48,703
Health
208
00:10:51,007 --> 00:10:53,311
Let's make it a bright red
209
00:10:53,823 --> 00:10:55,871
There we go there some healthier for us
210
00:10:56,127 --> 00:10:57,151
A little bit pink
211
00:10:57,919 --> 00:10:58,687
And
212
00:10:59,455 --> 00:11:02,527
What I want to do is actually just drag this to a prefabs
213
00:11:03,295 --> 00:11:04,319
Right there
214
00:11:04,575 --> 00:11:06,367
Creating original prefab
215
00:11:06,623 --> 00:11:08,671
So now we have a health item
216
00:11:09,951 --> 00:11:10,975
In a coin item
217
00:11:11,999 --> 00:11:14,303
Well is this actually going to be havenshealth
218
00:11:14,559 --> 00:11:16,607
Not yet let's go hen
219
00:11:18,143 --> 00:11:19,167
Johnny dough's
220
00:11:19,679 --> 00:11:23,519
And how we have this collectible pony here on her health game object
221
00:11:24,031 --> 00:11:26,079
Let's be sure we said it to health
222
00:11:26,847 --> 00:11:29,151
Alright so if we go back into your script here
223
00:11:29,919 --> 00:11:34,527
You can see here that it says if I am type is coin flip the coin
224
00:11:35,039 --> 00:11:36,831
If item type is health
225
00:11:38,879 --> 00:11:40,927
Well I didn't type is said to help
226
00:11:41,695 --> 00:11:45,023
Therefore it should increase our health value
227
00:11:45,791 --> 00:11:49,887
So nothing's going to happen to our national health bar
228
00:11:50,399 --> 00:11:51,167
Just yet
229
00:11:51,679 --> 00:11:54,751
All that's going to happen is going to add some health
230
00:11:55,263 --> 00:11:56,543
It's going to play
231
00:11:58,079 --> 00:12:00,383
Take a look at our health value here
232
00:12:00,639 --> 00:12:03,199
100 if I collect this
233
00:12:03,455 --> 00:12:04,991
But now it's 101
234
00:12:05,503 --> 00:12:06,015
Well
235
00:12:06,271 --> 00:12:09,343
We really don't want to go over 101 do we
236
00:12:10,111 --> 00:12:15,999
So what we're going to do is just create a simple condition inside of the condition we've only written here
237
00:12:16,767 --> 00:12:18,815
Wheeler Dealers just go if
238
00:12:19,583 --> 00:12:20,351
New player
239
00:12:20,863 --> 00:12:24,703
Health is smaller than a value of 100
240
00:12:25,471 --> 00:12:26,239
Then
241
00:12:28,031 --> 00:12:29,055
Working as an elf
242
00:12:31,871 --> 00:12:32,895
That's great
243
00:12:33,407 --> 00:12:34,687
The now
244
00:12:34,943 --> 00:12:38,527
Go back into unity sofa health is currently 100
245
00:12:39,039 --> 00:12:40,319
Play
246
00:12:41,343 --> 00:12:42,879
We should be able to collect the health
247
00:12:43,135 --> 00:12:45,695
But it's not actually an increase the value
248
00:12:45,951 --> 00:12:47,999
Pretty much Max Tell right
249
00:12:49,791 --> 00:12:52,351
So let's go ahead and set our health by default
250
00:12:53,119 --> 00:12:55,423
250 just for testing purposes
251
00:12:55,679 --> 00:12:56,447
In here play
252
00:13:01,055 --> 00:13:02,079
Now it's 51
253
00:13:02,335 --> 00:13:03,871
Awesome that's perfect
254
00:13:04,383 --> 00:13:10,015
So now that we've actually got the ability to collect these red orbs to get health
255
00:13:10,271 --> 00:13:12,831
Now I want to make it actually reflected
256
00:13:13,087 --> 00:13:14,879
In the percentages
257
00:13:15,135 --> 00:13:16,671
Are the health bars with
258
00:13:17,951 --> 00:13:19,487
Hi so our health
259
00:13:19,743 --> 00:13:20,511
Variable
260
00:13:21,023 --> 00:13:22,559
My actual player
261
00:13:22,815 --> 00:13:27,679
Is it raining right we like to help and it goes up by 1 so from 50 to 51
262
00:13:28,191 --> 00:13:29,727
Nothing happening with the actual
263
00:13:29,983 --> 00:13:35,103
Health bar UI so we need to make that reflective of the actual value
264
00:13:35,871 --> 00:13:39,967
Well you remember we have a function inside of a new player called update UI
265
00:13:40,479 --> 00:13:46,623
The update UI is basically just going to say hey what's the coins value what's the health value what's RAM
266
00:13:46,879 --> 00:13:52,255
Are you going to check for all these things every time you collect something and it's going to try and reflect it in the UI
267
00:13:52,767 --> 00:13:57,631
So what's writing pseudocode here to help us better understand how I'm going to write this equation
268
00:13:58,399 --> 00:14:00,447
Basically wanted to set
269
00:14:00,703 --> 00:14:01,983
The health bar
270
00:14:02,751 --> 00:14:03,519
With
271
00:14:04,543 --> 00:14:06,591
To a percentage
272
00:14:07,871 --> 00:14:09,663
Of its original value
273
00:14:10,175 --> 00:14:16,319
Ok so we're going to do this is something like see here we need a multiplier
274
00:14:16,575 --> 00:14:17,855
We need a x
275
00:14:18,111 --> 00:14:20,671
The original health bar with
276
00:14:20,927 --> 00:14:27,071
Do something like health bar Dad x x x a percentage of a value
277
00:14:27,327 --> 00:14:33,471
Going to be x x something like .45 something like that so it shrinks down to half of its size
278
00:14:33,727 --> 00:14:35,007
How we get that value
279
00:14:35,263 --> 00:14:38,079
What's the apprentices here in try and figure out what this would be
280
00:14:38,591 --> 00:14:41,151
Well it's going to be my current health
281
00:14:41,663 --> 00:14:43,711
/ my Max health
282
00:14:43,967 --> 00:14:44,735
Ok
283
00:14:45,759 --> 00:14:48,319
So what is my maximum health value
284
00:14:48,831 --> 00:14:50,623
When I actually have something like that
285
00:14:51,135 --> 00:14:53,951
Swansea this what's a private integer
286
00:14:54,463 --> 00:14:55,999
Call Max health
287
00:14:56,767 --> 00:14:59,839
Let's make our maxhealth 100 ok
288
00:15:00,095 --> 00:15:03,423
Our health is currently 100 as well that's ok
289
00:15:04,191 --> 00:15:09,823
So now health / Max health is going to be some kind of a decimals of my health is it 50
290
00:15:10,847 --> 00:15:15,199
50 / Max health is 50% or .5
291
00:15:15,711 --> 00:15:20,319
So health bar that x x x 50%
292
00:15:20,575 --> 00:15:22,623
Should kind of do the trick right
293
00:15:22,879 --> 00:15:24,159
Well not exactly
294
00:15:24,415 --> 00:15:30,559
Actually needs to be the original value to health bar or rage
295
00:15:31,071 --> 00:15:32,095
Dad x
296
00:15:32,607 --> 00:15:38,751
So what's the original size what was the original size of the health bar then we're going x x at present
297
00:15:39,519 --> 00:15:42,335
So how do we write this in actual code
298
00:15:42,591 --> 00:15:45,407
It would be something like health bar
299
00:15:45,919 --> 00:15:46,687
Dad
300
00:15:46,943 --> 00:15:47,967
Transform
301
00:15:48,479 --> 00:15:50,015
Recttransform Meadows
302
00:15:50,783 --> 00:15:52,319
Size Delta
303
00:15:53,087 --> 00:15:53,855
Equals
304
00:15:54,111 --> 00:15:56,159
New vector2
305
00:15:56,927 --> 00:15:58,975
Ok here is where we do that equation
306
00:15:59,231 --> 00:16:02,815
Health bar rage size.xl
307
00:16:03,071 --> 00:16:07,679
X x printezis health /
308
00:16:08,447 --> 00:16:09,471
Max health
309
00:16:09,727 --> 00:16:11,775
I know this is confusing
310
00:16:12,543 --> 00:16:16,383
And it seems like I'm smart and I know exactly what I'm doing here
311
00:16:16,639 --> 00:16:21,247
But I actually had it sorted take a breather and puzzle little bit while doing this tutorial evening
312
00:16:21,759 --> 00:16:24,063
Really think about what is equation is
313
00:16:24,831 --> 00:16:28,671
Ok so we've got some squiggly lines looks like we're not actually
314
00:16:28,927 --> 00:16:35,071
That's right we need to put a y value in here what's the weather you that's the height we want it to be identical
315
00:16:35,327 --> 00:16:39,167
Just help bar directions form delta 0.1
316
00:16:40,447 --> 00:16:41,215
Semicolon
317
00:16:42,751 --> 00:16:47,103
So why on earth is this equation
318
00:16:47,359 --> 00:16:50,175
Let's just break it down as simple as we can guys
319
00:16:51,199 --> 00:16:53,759
So was setting the size of our health bar
320
00:16:54,015 --> 00:16:55,807
That's called size Delta
321
00:16:56,063 --> 00:16:59,647
And that is a variable of the recttransform component
322
00:17:00,159 --> 00:17:02,463
We're going to set that to a new vector to
323
00:17:03,231 --> 00:17:08,863
Who is X and Y or in this case with or height
324
00:17:09,375 --> 00:17:11,935
Premier Inn why perimeter ok
325
00:17:12,191 --> 00:17:14,495
What about the experiment are really quick
326
00:17:15,263 --> 00:17:16,799
This is the actual whip
327
00:17:19,359 --> 00:17:23,199
So we're going to set the width to be the original size
328
00:17:24,479 --> 00:17:26,015
Times that percentage
329
00:17:26,783 --> 00:17:27,807
Bet calculator
330
00:17:28,575 --> 00:17:29,855
From my current health
331
00:17:30,623 --> 00:17:31,903
÷ maxhealth
332
00:17:32,415 --> 00:17:34,207
Search my credit is 50
333
00:17:34,463 --> 00:17:35,999
100
334
00:17:36,511 --> 00:17:37,535
That's .5
335
00:17:38,303 --> 00:17:40,607
So it's the original size of the bar
336
00:17:41,119 --> 00:17:41,887
In the wet
337
00:17:42,399 --> 00:17:44,191
X x 0.5
338
00:17:46,239 --> 00:17:48,031
Why you here is the height
339
00:17:48,287 --> 00:17:51,615
When are we doing you're saying don't change it keep it exactly what it is
340
00:17:51,871 --> 00:17:54,943
How far Direct transform that size delta that's why
341
00:17:55,967 --> 00:17:57,503
So nothing is going to be tweet here
342
00:17:59,551 --> 00:18:03,135
Ok so I think they will do it let's test this year
343
00:18:03,647 --> 00:18:05,951
Go hip playing see what happens
344
00:18:06,463 --> 00:18:08,511
Nothing should happen with a health bar yet
345
00:18:09,279 --> 00:18:14,911
Currently with our current script is if we collect a health item so that's right
346
00:18:15,423 --> 00:18:16,703
Oh my goodness
347
00:18:16,959 --> 00:18:22,591
So it is 0 or 21 take a look
348
00:18:23,103 --> 00:18:24,895
Exactly 0
349
00:18:25,407 --> 00:18:27,967
Let's try and diagnose why that happened
350
00:18:28,223 --> 00:18:31,039
Going to happen all out with you guys when you're making your game
351
00:18:31,551 --> 00:18:33,343
White just happened
352
00:18:33,599 --> 00:18:34,623
To my line of code
353
00:18:35,135 --> 00:18:36,671
So I talked about debugging
354
00:18:36,927 --> 00:18:38,463
These kinds of errors
355
00:18:39,231 --> 00:18:44,351
OK well let's go ahead in remove all of this comment stuff we don't need that
356
00:18:45,631 --> 00:18:51,775
Let's go ahead in figure out what is going on here some of you might actually see exactly
357
00:18:52,031 --> 00:18:54,591
Going on in if you do bravo to you
358
00:18:54,847 --> 00:18:58,431
But I'm going to go step-by-step in figure out what's going on here
359
00:18:58,687 --> 00:19:01,759
Well what are health borough Ridge size
360
00:19:02,015 --> 00:19:03,295
What is the current value
361
00:19:03,807 --> 00:19:09,951
Let's go home hip play and make sure we get that value correct when I want to do is go through each portion of my
362
00:19:10,463 --> 00:19:13,023
To make sure everything is the correct value
363
00:19:13,791 --> 00:19:15,839
Securly it's 8:16
364
00:19:16,095 --> 00:19:16,863
Ok
365
00:19:19,679 --> 00:19:20,959
Let's see here
366
00:19:21,471 --> 00:19:23,519
So that's 816
367
00:19:24,287 --> 00:19:25,311
X
368
00:19:25,567 --> 00:19:26,591
Times our health
369
00:19:27,871 --> 00:19:29,151
Which is 50
370
00:19:29,663 --> 00:19:31,455
÷ or Max health
371
00:19:32,223 --> 00:19:34,271
1 x 100
372
00:19:34,783 --> 00:19:39,391
Just go ahead and do a little bit of a debug.log
373
00:19:39,647 --> 00:19:40,415
Health
374
00:19:42,207 --> 00:19:43,999
Percentage
375
00:19:44,255 --> 00:19:45,279
Is
376
00:19:46,559 --> 00:19:48,351
Plus animals copy
377
00:19:49,631 --> 00:19:50,655
Is value here
378
00:19:53,471 --> 00:19:55,775
Ok so we're going to find out what the health percentage is
379
00:19:57,823 --> 00:19:59,103
What's going on here play
380
00:20:01,919 --> 00:20:02,687
0
381
00:20:04,479 --> 00:20:06,015
I think I know what's going on
382
00:20:07,295 --> 00:20:08,575
What we need to do
383
00:20:09,087 --> 00:20:11,391
I'm actually glad it happened because I need to tell you about
384
00:20:12,671 --> 00:20:14,975
Define dividing one integer
385
00:20:15,231 --> 00:20:16,255
Another integer
386
00:20:16,767 --> 00:20:19,071
It's going to output 0
387
00:20:19,583 --> 00:20:20,863
And the reason why is because
388
00:20:21,375 --> 00:20:23,935
These are floats these are integers
389
00:20:24,191 --> 00:20:25,727
How we convert them to a float
390
00:20:26,495 --> 00:20:29,567
Actually I got to do is just type float in front of One
391
00:20:30,079 --> 00:20:35,199
Inflow in front of another integer so now they seem to do is say what's the healthy to do
392
00:20:35,711 --> 00:20:36,991
Convert that to a float
393
00:20:37,759 --> 00:20:41,087
What's the max out integer into a float
394
00:20:41,599 --> 00:20:42,879
Enniskillen divider 2
395
00:20:43,903 --> 00:20:45,183
So let's see if he bugs
396
00:20:46,207 --> 00:20:47,487
The proper calculation
397
00:20:49,279 --> 00:20:55,423
Awesome OK now it's .51 time to do is go back in the net script here and just had the
398
00:20:58,239 --> 00:21:00,287
Float / float
399
00:21:02,079 --> 00:21:04,383
Then we can delete the debug here
400
00:21:04,895 --> 00:21:06,175
And it should
401
00:21:07,199 --> 00:21:08,479
Set our health bar
402
00:21:08,735 --> 00:21:11,039
To be about 51%
403
00:21:11,295 --> 00:21:12,575
Original value
404
00:21:13,599 --> 00:21:17,696
Artem ok sorry how far is adjusting properly
405
00:21:17,952 --> 00:21:21,280
The other thing we got to do is your guys as well when we have play
406
00:21:21,536 --> 00:21:23,584
You notice that a health is 50 here
407
00:21:24,352 --> 00:21:30,496
The Mark self is 100 but why is the bar none A50 it should be that way the moment
408
00:21:30,752 --> 00:21:31,264
Start the game
409
00:21:31,776 --> 00:21:32,288
Well
410
00:21:32,544 --> 00:21:37,408
You probably thought of it before I did are we going to do is make this update UI
411
00:21:37,664 --> 00:21:38,432
Cabin
412
00:21:38,688 --> 00:21:40,480
In the start function as well
413
00:21:41,248 --> 00:21:44,320
So what you going to do it right here update you why
414
00:21:44,576 --> 00:21:48,928
So the moment that unity starts the game then we hit play
415
00:21:49,184 --> 00:21:50,464
It's going to burst
416
00:21:50,976 --> 00:21:52,512
Variables
417
00:21:53,024 --> 00:21:56,096
And just like a speed reader he's going to jump to The Voice start here
418
00:21:56,352 --> 00:21:58,656
Restarting my game
419
00:21:58,912 --> 00:22:04,032
I need to first set the health bar original size variable to match the health bar
420
00:22:04,544 --> 00:22:10,688
And then I'm going to go ahead and update my uy meaning I'm going to take a look at all these calculations here
421
00:22:10,944 --> 00:22:12,736
Make the appropriate adjustments
422
00:22:14,272 --> 00:22:15,552
That's it saving
423
00:22:16,320 --> 00:22:17,344
Tiny unity
424
00:22:18,112 --> 00:22:19,392
How far
425
00:22:19,904 --> 00:22:22,976
The moment we have play the moment the death start function fires
426
00:22:23,232 --> 00:22:24,256
Is it raining down
427
00:22:25,792 --> 00:22:27,584
Perfect awesome
428
00:22:27,840 --> 00:22:32,704
I love it and you can see it to iterate it there so let's go ahead in ads and health
429
00:22:33,472 --> 00:22:34,240
To the game
430
00:22:35,008 --> 00:22:36,288
Sad one here
431
00:22:37,312 --> 00:22:41,408
Maybe some in the sky right here
432
00:22:41,920 --> 00:22:43,968
Periods and healthy and here
433
00:22:44,224 --> 00:22:50,368
Is always really fine and collectables collectables and just going to make your game so fun and we make a little
434
00:22:50,624 --> 00:22:52,160
Play two player on a jump in that direction
435
00:22:52,672 --> 00:22:54,720
Really really cold here so let's go ahead in
436
00:22:54,976 --> 00:22:55,744
Play
437
00:23:01,120 --> 00:23:02,144
Awesome
438
00:23:06,496 --> 00:23:08,800
Well it looks like the health bar
439
00:23:09,568 --> 00:23:13,152
Isn't updating and that's a little strange will take a look and see what's going on
440
00:23:13,920 --> 00:23:15,712
For some reason
441
00:23:15,968 --> 00:23:20,320
Those prefabs that we just added are not adding health to the player
442
00:23:21,088 --> 00:23:21,856
Why is that
443
00:23:24,160 --> 00:23:25,184
I see
444
00:23:25,440 --> 00:23:28,000
Looks like this is a great example
445
00:23:28,256 --> 00:23:30,304
I've just double checking your prefabs
446
00:23:30,560 --> 00:23:33,376
Looks like if we double click on her health prefab
447
00:23:34,144 --> 00:23:37,984
It looks like the item type wasn't set correctly for a health prefab
448
00:23:38,496 --> 00:23:40,544
Let's be sure we said that to health
449
00:23:41,056 --> 00:23:42,592
Go back to the scene
450
00:23:43,104 --> 00:23:45,664
Just double checking m Oliver health
451
00:23:46,432 --> 00:23:48,992
Ok so the item type is set correctly
452
00:23:49,248 --> 00:23:50,528
How much is drag these
453
00:23:50,784 --> 00:23:52,064
Angela one as well
454
00:23:52,320 --> 00:23:53,856
Just having organised
455
00:23:54,112 --> 00:23:55,392
Now when we have play
456
00:23:56,928 --> 00:24:01,536
You can scale up a game window just a little bit to see the iteration of the health bar
457
00:24:01,792 --> 00:24:04,096
Alright good it's going outputs go
458
00:24:04,608 --> 00:24:05,632
Over here
459
00:24:07,424 --> 00:24:08,448
Good ass
460
00:24:09,728 --> 00:24:11,264
Slowly iterating
461
00:24:11,520 --> 00:24:14,592
What's your notice better coins are no longer updating now
462
00:24:14,848 --> 00:24:18,944
What is going on with ticklish here it's go back in your script in
463
00:24:19,200 --> 00:24:20,480
Are you out this bug as well
464
00:24:21,504 --> 00:24:25,856
I'm keeping these bags in this tutorial guys because I want you guys to understand slowly
465
00:24:26,368 --> 00:24:28,160
How to fix bugs
466
00:24:28,416 --> 00:24:33,536
So if you're going or collectible script here if item type is coin or going to add Torpoint
467
00:24:34,304 --> 00:24:36,352
And then we're going to update the UI
468
00:24:36,608 --> 00:24:38,656
Update UI function
469
00:24:39,424 --> 00:24:44,288
Looks like that's probably set up so let's go ahead and jump into unity
470
00:24:44,544 --> 00:24:48,640
BBC what's going on it's like one of these coins here I'll take a scripture ok
471
00:24:48,896 --> 00:24:49,920
Hurricanes
472
00:24:50,432 --> 00:24:51,456
Oh my goodness
473
00:24:51,968 --> 00:24:58,112
Item type is it the ML I have no idea why they happened but that's ok that's why we use
474
00:24:58,368 --> 00:24:58,880
Prefabs
475
00:24:59,136 --> 00:25:01,184
Double click on a coin prefab
476
00:25:01,696 --> 00:25:02,976
In a project folder
477
00:25:03,744 --> 00:25:05,792
Change the item type 2 coin
478
00:25:08,352 --> 00:25:11,680
Now it's a van hopefully everything is updating accordingly
479
00:25:13,984 --> 00:25:15,520
Health
480
00:25:17,568 --> 00:25:18,848
The coin
481
00:25:19,360 --> 00:25:20,384
Yeah ok
482
00:25:20,896 --> 00:25:23,200
Item types are working fine
483
00:25:24,736 --> 00:25:25,760
Perfect
484
00:25:28,064 --> 00:25:28,576
Awesome
485
00:25:28,832 --> 00:25:31,392
There's a quick recap guys
486
00:25:31,648 --> 00:25:33,184
Your variables
487
00:25:33,440 --> 00:25:35,488
For health and ammo
488
00:25:35,744 --> 00:25:36,512
Coins
489
00:25:36,768 --> 00:25:42,912
All that stuff it's not stored in the UI DUI is simply reflect
490
00:25:43,168 --> 00:25:44,192
The variables
491
00:25:44,448 --> 00:25:46,496
Data stored somewhere else
492
00:25:46,752 --> 00:25:49,568
In this case for storing those variables in a
493
00:25:49,824 --> 00:25:54,432
Assistant script that means a script that's going to be running throughout the entire game
494
00:25:54,688 --> 00:26:00,832
In our case it's the new player this player is always going to be in the game so were storing
495
00:26:01,088 --> 00:26:05,952
Inventory variables like health my coins collected
496
00:26:06,464 --> 00:26:08,512
Does are all stored in the Script
497
00:26:09,024 --> 00:26:10,560
In the UI elements
498
00:26:11,328 --> 00:26:12,352
Reflects those
499
00:26:13,376 --> 00:26:16,704
Using a simple function called update UI
500
00:26:17,728 --> 00:26:20,800
We fire this function or call this function
501
00:26:22,080 --> 00:26:28,224
From other scripts so we can call that function from the collectible script and see it's been cold here
502
00:26:28,480 --> 00:26:31,552
Or if we had an enemy scripting when the enemy hit the player
503
00:26:31,808 --> 00:26:33,344
In the health decreased
504
00:26:33,600 --> 00:26:35,648
You just buy that functions again
505
00:26:35,904 --> 00:26:41,024
That's why we have a single function called update by inside of one
506
00:26:41,536 --> 00:26:43,840
Class and that's the new player class
507
00:26:44,352 --> 00:26:49,472
Because I want to give a fire that from all kinds of other script a collectible script
508
00:26:49,984 --> 00:26:52,800
An enemy script maybe a boss script
509
00:26:53,056 --> 00:26:56,384
Maybe there's some traps in the game that can hurt you
510
00:26:56,896 --> 00:27:01,760
Or maybe there's some characters in the game that will give you 3000 coins
511
00:27:02,528 --> 00:27:06,624
No matter what or who is changing the variables of your inventory
512
00:27:07,392 --> 00:27:09,952
All we got to do is just updating you are
513
00:27:10,208 --> 00:27:14,048
With this simple coming and here new player that update UI
514
00:27:14,560 --> 00:27:17,120
And it's always going to go back to this function here
515
00:27:17,376 --> 00:27:19,680
Check the variables check your inventory
516
00:27:19,936 --> 00:27:22,240
And then update the UI accordingly
517
00:27:23,008 --> 00:27:29,152
So that is how you I generally works and games you have one big function here that can update the UI
518
00:27:29,408 --> 00:27:34,784
Based on your inventory so that a ton about the classes can use that single function
519
00:27:35,040 --> 00:27:39,392
Instead of writing of that function inside of every single class
520
00:27:39,648 --> 00:27:41,440
That wants to update the UI
521
00:27:41,952 --> 00:27:48,096
This doesn't make sense don't worry these kind of principles that can be used over and over and over and kind of research
522
00:27:48,608 --> 00:27:51,680
As we work through this tutorial to create our 2D game
37796
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.