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
What if I wanted the player to get hurt
2
00:00:13,056 --> 00:00:16,128
Whenever they touched the edges of this frame
3
00:00:16,896 --> 00:00:19,200
Maybe you know we could put spikes
4
00:00:19,456 --> 00:00:20,992
On the edges of the frame
5
00:00:21,248 --> 00:00:22,784
Are maybe they were enemies
6
00:00:23,296 --> 00:00:24,576
That were on the edge of the frame
7
00:00:25,344 --> 00:00:27,392
What the weather we would do this is actually
8
00:00:27,648 --> 00:00:29,184
Just add another command
9
00:00:29,696 --> 00:00:31,744
Inside of this condition
10
00:00:32,000 --> 00:00:33,280
So we could say
11
00:00:33,536 --> 00:00:34,560
What's a health
12
00:00:34,816 --> 00:00:35,840
- equals
13
00:00:37,120 --> 00:00:37,632
1
14
00:00:39,936 --> 00:00:40,704
What about
15
00:00:41,216 --> 00:00:41,984
Here as well
16
00:00:42,240 --> 00:00:44,032
Health - = 1
17
00:00:47,616 --> 00:00:48,128
Ok
18
00:00:48,384 --> 00:00:49,152
Here as well
19
00:00:49,408 --> 00:00:49,920
Health
20
00:00:50,176 --> 00:00:51,456
- = 1
21
00:00:52,736 --> 00:00:54,016
And then health
22
00:00:55,040 --> 00:00:56,320
- = 1
23
00:00:57,088 --> 00:00:57,856
So we have
24
00:00:58,368 --> 00:00:59,648
Each condition
25
00:01:00,123 --> 00:01:02,875
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
26
00:01:02,876 --> 00:01:04,000
Setting the transform value in also
27
00:01:04,512 --> 00:01:05,280
Removing the hair
28
00:01:06,560 --> 00:01:08,352
The one on Saturday
29
00:01:08,864 --> 00:01:12,192
Maybe debug.log let's say
30
00:01:12,448 --> 00:01:12,960
Hurt
31
00:01:14,496 --> 00:01:15,264
And then
32
00:01:16,288 --> 00:01:19,616
Plus what the actual health is so they're going to display
33
00:01:19,872 --> 00:01:22,688
That I was hurt and and also what my health is
34
00:01:22,944 --> 00:01:26,784
What skimmia Rubella maybe put a calling innerspace
35
00:01:28,064 --> 00:01:29,600
And we can put that there
36
00:01:31,648 --> 00:01:32,160
Here
37
00:01:32,416 --> 00:01:33,696
And then was so pretty
38
00:01:33,952 --> 00:01:34,464
Hear it
39
00:01:34,976 --> 00:01:37,024
Ok let's go into unity
40
00:01:37,280 --> 00:01:39,840
To get your health is currently set to 25
41
00:01:41,120 --> 00:01:42,912
Play here and see what happens
42
00:01:45,216 --> 00:01:47,008
I got the right I should get her
43
00:01:47,776 --> 00:01:48,544
There we go
44
00:01:49,056 --> 00:01:54,176
So now I helped is negative 191 so were certainly already dead that happened pretty fast
45
00:01:54,432 --> 00:01:56,480
And you can see that it's actually displaying
46
00:01:57,504 --> 00:02:00,576
What are hurt value or a health is as we had
47
00:02:01,088 --> 00:02:01,600
The what
48
00:02:04,416 --> 00:02:05,184
What about the top
49
00:02:05,952 --> 00:02:06,464
Yeah
50
00:02:07,488 --> 00:02:09,536
At the bottom here was clear
51
00:02:09,792 --> 00:02:10,816
Play at the console
52
00:02:11,584 --> 00:02:13,120
Just so we can see it clearly
53
00:02:16,448 --> 00:02:19,264
My health is going down but for some reason it's not
54
00:02:19,776 --> 00:02:21,056
Displaying in the console
55
00:02:21,568 --> 00:02:22,592
Why is that
56
00:02:22,848 --> 00:02:24,128
Well
57
00:02:24,640 --> 00:02:25,920
When you're writing a script
58
00:02:27,456 --> 00:02:28,736
Sometimes you're going to forget
59
00:02:29,760 --> 00:02:30,528
Include
60
00:02:31,808 --> 00:02:34,112
Certain parts in each condition
61
00:02:34,880 --> 00:02:41,024
I can be a real pain in there is how we basically have a lot of redundancy here and redundancy is essentially
62
00:02:41,536 --> 00:02:43,072
The same line of code
63
00:02:43,328 --> 00:02:44,864
Over and over again
64
00:02:45,632 --> 00:02:48,192
What we can actually put this all in one place
65
00:02:48,960 --> 00:02:50,496
Search delete this
66
00:02:51,008 --> 00:02:51,776
This
67
00:02:52,544 --> 00:02:53,056
This
68
00:02:53,312 --> 00:02:56,640
Copy this really quick so there's just can't be there
69
00:02:58,432 --> 00:03:03,296
And let's see here let's go all the way past the update
70
00:03:03,808 --> 00:03:04,832
What's clean this up to
71
00:03:05,600 --> 00:03:08,416
So this is a function right here ok
72
00:03:09,184 --> 00:03:11,232
Update is a function
73
00:03:11,488 --> 00:03:12,512
In a function
74
00:03:13,280 --> 00:03:17,632
Is usually started with these little curly brackets select really break
75
00:03:18,144 --> 00:03:20,704
You can follow the dotted line all the way down
76
00:03:21,216 --> 00:03:23,264
To its closing bracket
77
00:03:23,520 --> 00:03:25,056
Not if you click next to it
78
00:03:25,312 --> 00:03:27,360
I doubt you'll see it's highlighted blue
79
00:03:27,616 --> 00:03:30,176
You can see where it's closed with the other highlighted
80
00:03:31,968 --> 00:03:34,272
So that's a closed function
81
00:03:34,528 --> 00:03:36,064
So we can start a new function
82
00:03:36,576 --> 00:03:40,672
What we can do is type void and we'll talk about what a boy means in a second
83
00:03:40,928 --> 00:03:41,696
Boys
84
00:03:42,464 --> 00:03:42,976
Hurt
85
00:03:43,488 --> 00:03:46,560
We can just pray and name in this case it's called her
86
00:03:47,328 --> 00:03:48,352
Printer sees
87
00:03:48,608 --> 00:03:50,656
Open it up
88
00:03:51,424 --> 00:03:52,704
And now we have a new
89
00:03:53,728 --> 00:03:54,496
Function
90
00:03:55,776 --> 00:03:58,080
Pasting those values
91
00:03:59,872 --> 00:04:03,200
So now we can actually use this function
92
00:04:03,712 --> 00:04:05,248
Over and over again
93
00:04:05,504 --> 00:04:06,528
The thing
94
00:04:06,784 --> 00:04:09,600
Anytime you create a custom function like this
95
00:04:09,856 --> 00:04:11,392
It only runs
96
00:04:11,904 --> 00:04:12,928
When you tell it to
97
00:04:13,696 --> 00:04:15,232
So this update function here
98
00:04:16,256 --> 00:04:17,791
This runs all the time
99
00:04:18,559 --> 00:04:23,679
Unity wall run this over and over and over again like we discussed in the previous tutorial videos
100
00:04:25,471 --> 00:04:27,519
A custom function like this
101
00:04:28,287 --> 00:04:33,407
You can tell us customer because of the green or yellow text your account looks like puke yellow doesn't it
102
00:04:33,663 --> 00:04:36,735
That is a custom function if it's only going to run
103
00:04:36,991 --> 00:04:38,015
When we tell her to
104
00:04:39,039 --> 00:04:39,551
So
105
00:04:40,319 --> 00:04:41,855
We save it and hit play
106
00:04:45,183 --> 00:04:48,767
You noticed that nothing gets printed in the console window
107
00:04:51,071 --> 00:04:53,631
That function exists we just haven't used it
108
00:04:53,887 --> 00:04:55,423
It never occurred
109
00:04:56,191 --> 00:04:58,495
Because we haven't told you need to use
110
00:04:59,263 --> 00:05:02,079
We've created the function it exists
111
00:05:02,591 --> 00:05:06,175
Basically a weapon or a tool that we have available to us
112
00:05:06,431 --> 00:05:07,711
We haven't used it
113
00:05:08,479 --> 00:05:08,991
Cell
114
00:05:09,759 --> 00:05:11,807
Are we going to do is simply
115
00:05:12,831 --> 00:05:13,343
Put it
116
00:05:14,367 --> 00:05:14,879
Here
117
00:05:15,391 --> 00:05:16,671
So what this means is
118
00:05:17,951 --> 00:05:19,231
Call the function
119
00:05:19,487 --> 00:05:19,999
Hurt
120
00:05:21,791 --> 00:05:27,935
Another way of putting it instead of using the word call it's basically saying perform the function
121
00:05:28,447 --> 00:05:33,055
So if my transformed value is greater than 8.35 in the x axis
122
00:05:33,311 --> 00:05:34,847
Natalie am I going to
123
00:05:35,615 --> 00:05:37,663
Put the X value 8.3 f
124
00:05:37,919 --> 00:05:40,223
I'm also going to call the heart function
125
00:05:40,479 --> 00:05:42,271
Which is going to track my health
126
00:05:42,783 --> 00:05:43,551
And also
127
00:05:45,087 --> 00:05:46,623
Print to the console window
128
00:05:47,903 --> 00:05:49,439
We can put this in
129
00:05:51,487 --> 00:05:51,999
3
130
00:05:53,791 --> 00:05:56,351
All four of my conditions
131
00:06:01,727 --> 00:06:03,519
What's a play and make sure it works
132
00:06:08,895 --> 00:06:09,663
There we go
133
00:06:09,919 --> 00:06:10,943
So we're getting
134
00:06:13,759 --> 00:06:15,039
The health printed
135
00:06:17,087 --> 00:06:17,855
And also
136
00:06:19,391 --> 00:06:21,439
Our health is actually subtracting over here
137
00:06:22,719 --> 00:06:23,487
Very
138
00:06:27,583 --> 00:06:28,607
So you noticed that
139
00:06:30,911 --> 00:06:32,191
Everytime I touch
140
00:06:32,447 --> 00:06:35,007
The right side of the screen my health goes down
141
00:06:35,519 --> 00:06:36,543
Which is
142
00:06:36,799 --> 00:06:41,919
Kind of really unfair the player because they didn't really
143
00:06:42,431 --> 00:06:46,527
Wanna get heard damn many times they were really warned were they
144
00:06:46,783 --> 00:06:49,087
Well we can actually just create a counter
145
00:06:50,111 --> 00:06:51,903
Allows them to recover a little
146
00:06:52,671 --> 00:06:57,023
So basically what we want is if I'm on the right side of the screen I want to get hurt
147
00:06:57,279 --> 00:07:03,423
Wait 2 seconds her again wait 2 seconds her again wait 2 seconds hurt again
148
00:07:04,447 --> 00:07:08,287
The way that we can do that is put this all inside
149
00:07:08,543 --> 00:07:09,567
After her function
150
00:07:10,079 --> 00:07:12,383
Sebastian four conditions
151
00:07:12,639 --> 00:07:14,431
Aka statements
152
00:07:14,943 --> 00:07:16,991
Inside of actual functions
153
00:07:17,503 --> 00:07:19,807
So here's what we can do
154
00:07:20,063 --> 00:07:25,951
If that's right it on pseudocode if my recovery counter
155
00:07:26,463 --> 00:07:27,999
Is smaller than 2
156
00:07:28,511 --> 00:07:30,815
It's a greater than 2
157
00:07:31,071 --> 00:07:37,215
Then I can get hurt otherwise and else
158
00:07:38,239 --> 00:07:44,383
I won't I will be invincible
159
00:07:44,639 --> 00:07:46,687
Alright so
160
00:07:47,711 --> 00:07:50,015
Does recovery counter exist
161
00:07:50,527 --> 00:07:53,343
Meaning does this variable recovery counter
162
00:07:53,855 --> 00:07:54,879
Does that exist
163
00:07:55,391 --> 00:08:01,279
It is not so we need to declare it or another way of putting it is we need to birth it
164
00:08:01,535 --> 00:08:07,679
Don't actually just burp the recovery counter appear it doesn't need to be serialised and it doesn't
165
00:08:07,935 --> 00:08:12,543
Be public or private video call it recovery
166
00:08:13,055 --> 00:08:19,199
Show me spell it right make sure we declare what it actually is it the private flow
167
00:08:19,455 --> 00:08:24,319
Bounce by default 0 so we don't need an equals sign
168
00:08:25,855 --> 00:08:26,623
Alright
169
00:08:27,391 --> 00:08:29,951
So what will do is will say
170
00:08:31,231 --> 00:08:31,743
If
171
00:08:31,999 --> 00:08:33,535
Recovery counter
172
00:08:33,791 --> 00:08:37,119
Is greater than 2
173
00:08:38,655 --> 00:08:39,935
I can get hurt
174
00:08:46,591 --> 00:08:52,735
What's going on why do we have a red squiggly line underneath this closing bracket what it's because
175
00:08:52,991 --> 00:08:56,575
Missing an opening bracket somewhere where is that
176
00:08:56,831 --> 00:09:02,719
Well below every condition and also blow every function you need to make sure you're opening up that statement
177
00:09:02,975 --> 00:09:05,279
With an opening bracket so do that
178
00:09:05,791 --> 00:09:06,303
Here
179
00:09:06,559 --> 00:09:08,607
What's I get me two of them
180
00:09:08,863 --> 00:09:15,007
Visual Studio deliver computers that's ok what does backspace in now everything's fixed
181
00:09:15,263 --> 00:09:20,127
So if a recovery counter is greater than 2 then we can actually get her
182
00:09:20,895 --> 00:09:27,039
Otherwise it's not going to do anything and I can get hurting when I get to print anything to the console window so
183
00:09:27,295 --> 00:09:29,087
Save it out here and
184
00:09:29,343 --> 00:09:35,487
What's go ahead in actually serialise this field just so we can see what's happening inside of the unity editor
185
00:09:35,743 --> 00:09:38,047
Temporary serialisation
186
00:09:38,303 --> 00:09:39,327
So
187
00:09:39,583 --> 00:09:44,191
There is a recovery county down here that supply and see what happens
188
00:09:45,215 --> 00:09:46,239
Nothing is happening
189
00:09:47,263 --> 00:09:51,615
Well this is in a bank this is actually because well we just didn't finish our code
190
00:09:51,871 --> 00:09:53,919
We need the recovery counter
191
00:09:54,175 --> 00:09:56,479
To iterate up towards to
192
00:09:57,503 --> 00:10:00,063
So we need to write that in code
193
00:10:00,345 --> 00:10:02,504
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
194
00:10:02,505 --> 00:10:02,879
So where we ride the iteration
195
00:10:03,135 --> 00:10:04,415
Would it happen here
196
00:10:05,183 --> 00:10:07,487
Well if it happens inside of here
197
00:10:07,743 --> 00:10:13,887
That means that every time we get hurt the recovery counter will go up and we don't want that we want it to constantly
198
00:10:14,143 --> 00:10:16,703
Counting with actually put
199
00:10:17,215 --> 00:10:19,007
Somewhere inside of the update
200
00:10:19,519 --> 00:10:21,567
Cell
201
00:10:21,823 --> 00:10:24,639
When are we just read it you'll a threesome pseudocode
202
00:10:24,895 --> 00:10:31,039
Increase increase increase increase
203
00:10:31,295 --> 00:10:36,927
Recovery counter
204
00:10:37,183 --> 00:10:38,463
Wine
205
00:10:39,487 --> 00:10:45,631
Per second recovery counter you can do it this way recovery
206
00:10:45,887 --> 00:10:52,031
Equals recovery counter + 1 x x
207
00:10:52,287 --> 00:10:58,431
That's mass great it's still gonna work was cleaning up a little bit so as to
208
00:10:58,687 --> 00:11:01,503
+ = number + = basically means equals
209
00:11:01,759 --> 00:11:03,295
Recovery cancer Plus
210
00:11:03,551 --> 00:11:04,063
A number
211
00:11:04,319 --> 00:11:05,855
So plus
212
00:11:06,111 --> 00:11:12,255
Equals South recovery counter increases by 1 x x x
213
00:11:12,511 --> 00:11:18,655
What's the time 12 what's 1 x x at delta time was actually just time
214
00:11:18,911 --> 00:11:25,055
Member any value x x 1 is the same thing so
215
00:11:25,311 --> 00:11:26,847
Increase
216
00:11:28,127 --> 00:11:32,735
Bye time that there was a time so really it's just a counter just like a watch
217
00:11:32,991 --> 00:11:38,111
Is always going to be iterating and increasing the value of 1 per second
218
00:11:38,879 --> 00:11:42,207
Again this recovery counters always going to be taking up word
219
00:11:44,255 --> 00:11:46,047
Air for greater than 2
220
00:11:46,815 --> 00:11:48,095
Where they decrease the health
221
00:11:48,863 --> 00:11:50,399
Does saving out here
222
00:11:50,655 --> 00:11:53,215
Go back to Unity and hopefully
223
00:11:53,727 --> 00:11:55,775
Take a look at a recovery counter
224
00:11:56,031 --> 00:11:59,615
Ok so it's it's over 2 so that means I'm
225
00:11:59,871 --> 00:12:01,407
Capable of getting hurt
226
00:12:02,431 --> 00:12:03,711
But I'm getting hurt
227
00:12:04,223 --> 00:12:05,503
Why on earth
228
00:12:06,015 --> 00:12:12,159
Can I still get hurt so quickly what it's because a recovery counter is still over 2 and never goes back
229
00:12:12,415 --> 00:12:14,207
20 so are we going to do
230
00:12:14,463 --> 00:12:15,999
Is
231
00:12:16,255 --> 00:12:18,559
Set recovery cancer
232
00:12:18,815 --> 00:12:20,351
0
233
00:12:20,863 --> 00:12:22,143
When we get hurt
234
00:12:22,655 --> 00:12:25,983
So let's try it now
235
00:12:27,519 --> 00:12:29,823
Recovery garages at 2
236
00:12:31,103 --> 00:12:32,895
I get hurt there Goes Again
237
00:12:33,151 --> 00:12:33,663
Hurt
238
00:12:35,199 --> 00:12:35,711
Hurt
239
00:12:37,247 --> 00:12:37,759
Hurt
240
00:12:38,271 --> 00:12:40,575
So you can see we have
241
00:12:41,599 --> 00:12:44,415
The ability to recover every time we get hurt
242
00:12:44,671 --> 00:12:50,815
And this is just classic with any arcade game you give the player a little bit of wiggle room so they
243
00:12:51,071 --> 00:12:55,679
Get out of whatever situation they're in recover and then re engage
244
00:12:56,959 --> 00:13:03,103
In the reason I showed you this guys is not necessary to show you what every arcade game should have
245
00:13:03,615 --> 00:13:04,639
Bye
246
00:13:04,895 --> 00:13:07,199
What you can do inside of a function
247
00:13:07,967 --> 00:13:10,015
In this case it's the function hurt
248
00:13:11,039 --> 00:13:13,087
Can you imagine if I had all of this
249
00:13:14,111 --> 00:13:16,415
Pasting here paste of here
250
00:13:16,927 --> 00:13:20,255
Play say here pasted here
251
00:13:21,279 --> 00:13:27,423
Natalie is it incredibly messy and basically double the length
252
00:13:27,679 --> 00:13:28,447
The Script
253
00:13:28,959 --> 00:13:33,567
If I wanted to change anything about what happens when I get hurt less they want to do
254
00:13:33,823 --> 00:13:34,591
Maybe
255
00:13:35,359 --> 00:13:40,223
Get hurt by value 5 instead of 1 I have to change that value
256
00:13:40,479 --> 00:13:42,527
Four different times
257
00:13:43,295 --> 00:13:49,439
And that is a pain what I wanted the recovery calendar to be 3
258
00:13:49,695 --> 00:13:52,511
And you know if you forget to do one
259
00:13:52,767 --> 00:13:53,791
Condition down here
260
00:13:55,071 --> 00:14:01,215
And then you have play you go wondering why are some moments when I get hurt
261
00:14:01,471 --> 00:14:02,239
Along with another ones
262
00:14:02,495 --> 00:14:08,639
What's going on and that's why you want it all to be clean and in a single function
263
00:14:08,895 --> 00:14:09,663
The bottom here
264
00:14:09,919 --> 00:14:12,735
Now how do you know when you should use a function
265
00:14:12,991 --> 00:14:16,831
Well if you're ever riding the same line of code more than once
266
00:14:17,343 --> 00:14:18,623
Use it in a function
267
00:14:18,879 --> 00:14:20,671
That's a good rule of thumb
268
00:14:20,927 --> 00:14:22,463
You might wonder what time is
269
00:14:22,975 --> 00:14:24,255
Why did you put this
270
00:14:24,511 --> 00:14:25,535
Multiple times
271
00:14:26,559 --> 00:14:27,327
Well
272
00:14:28,095 --> 00:14:34,239
Actually separate lines of code because we have negative positive in a Nissan X value ship where
273
00:14:34,495 --> 00:14:35,519
Better y values
274
00:14:36,287 --> 00:14:42,431
Now there's certainly ways that we could clean this up these conditions you could actually use some clever
275
00:14:42,687 --> 00:14:47,039
Off the probably bring this all down into one conditional statement
276
00:14:47,551 --> 00:14:53,695
But for the purposes of this tutorial I think this is totally fine if we didn't want all of this
277
00:14:53,951 --> 00:14:58,047
Inside of the update function for everyone to keep you updated function really clean
278
00:14:58,303 --> 00:15:03,167
What would you could do if you could do void check boundaries
279
00:15:04,447 --> 00:15:06,751
Just paste all out in there
280
00:15:07,263 --> 00:15:13,407
And then I had a new is we can type our
281
00:15:13,663 --> 00:15:19,807
Here and then just type check boundaries
282
00:15:20,063 --> 00:15:24,415
Is it boundaries having that's what it is yeah it's with an a
283
00:15:24,671 --> 00:15:30,815
So we can have a function called check boundary survey in so now you know that it is ever in issue
284
00:15:31,071 --> 00:15:36,703
Boundaries instead of digging around in the update for it you can actually just go down to the function
285
00:15:37,215 --> 00:15:40,543
Can you give me and I'll make your functions alphabetical
286
00:15:40,799 --> 00:15:41,823
So instead of
287
00:15:42,079 --> 00:15:44,639
Check boundaries being below age
288
00:15:45,663 --> 00:15:50,271
You can copy and paste it above age
289
00:15:50,527 --> 00:15:56,671
So that you can easily sort through all of your functions in remember guys functions only happen
290
00:15:56,927 --> 00:15:58,975
Can you tell unity to do them
291
00:15:59,231 --> 00:15:59,743
Ok
292
00:16:00,255 --> 00:16:02,559
Now it's cool here is that
293
00:16:02,815 --> 00:16:07,167
Check boundaries is happening all the time because it's inside of the update
294
00:16:07,679 --> 00:16:11,775
Constantly updating sore constantly checking the boundaries
295
00:16:12,031 --> 00:16:15,359
Well inside a check boundaries we have the heart function
296
00:16:16,127 --> 00:16:22,271
So what using functions inside a function which is really cool in it clean things up and makes things
297
00:16:22,527 --> 00:16:28,671
Manageable now I understand that this might be a little bit confusing like nesting dolls right
298
00:16:29,183 --> 00:16:31,999
What are the recommended follow along with me
299
00:16:32,255 --> 00:16:38,399
Wiki the super simple 2D game kit and as we practise as we create this game Kit it's
300
00:16:38,655 --> 00:16:39,935
Become second nature for you
301
00:16:40,191 --> 00:16:45,055
So don't worry if it doesn't make much sense but we're going to keep doing these kinds of logic
302
00:16:45,311 --> 00:16:51,455
Over and over and over again
21747
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.