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,032
Banana cold is getting a little bit more complicated
2
00:00:12,288 --> 00:00:15,104
You may start to notice something called redundancy
3
00:00:15,616 --> 00:00:18,432
We've found the player here
4
00:00:18,688 --> 00:00:20,224
Also found him here
5
00:00:20,736 --> 00:00:23,552
We found the component here and we've also found here
6
00:00:24,064 --> 00:00:27,904
So we basically done the same thing twice when we should only do it once
7
00:00:28,160 --> 00:00:29,696
Why can't we have a reference
8
00:00:29,952 --> 00:00:35,584
To the player in the new player component only once so they have to do this over and over and over again
9
00:00:36,096 --> 00:00:42,240
Wine this is a lot of typing so for example if I wanted to do a lot of different things with the new
10
00:00:42,496 --> 00:00:45,824
Describe so what if ontriggerenter I also wanted to
11
00:00:46,080 --> 00:00:52,224
No maybe set the m o as well I have to go game object that fine player oh my goodness
12
00:00:52,480 --> 00:00:58,624
Takes forever I don't like coding I hate my life we don't want to do this that's just a mess
13
00:00:59,136 --> 00:00:59,904
So
14
00:01:00,123 --> 00:01:02,363
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
15
00:01:02,364 --> 00:01:02,208
There's two ways that we can solve this
16
00:01:02,720 --> 00:01:06,048
First way is to create a reference
17
00:01:06,560 --> 00:01:07,328
The player
18
00:01:08,352 --> 00:01:09,632
So we can do this
19
00:01:09,888 --> 00:01:11,424
Like this we can say
20
00:01:11,680 --> 00:01:12,960
New player
21
00:01:13,728 --> 00:01:14,240
Is
22
00:01:15,008 --> 00:01:15,776
Cold
23
00:01:16,544 --> 00:01:17,568
New player
24
00:01:17,824 --> 00:01:20,128
Is a = game object
25
00:01:22,176 --> 00:01:24,480
Find new player
26
00:01:26,016 --> 00:01:28,064
Getcomponent
27
00:01:28,576 --> 00:01:31,648
New player not our doing the same as acting
28
00:01:32,160 --> 00:01:33,184
We're doing here
29
00:01:34,720 --> 00:01:36,768
That's what new player is
30
00:01:37,024 --> 00:01:40,864
Then are we going to do is go and replace this to new player
31
00:01:41,376 --> 00:01:42,144
And then
32
00:01:43,424 --> 00:01:44,448
New player
33
00:01:46,496 --> 00:01:52,640
What we just done is we've created just like we do AP remember we can create variables up here before the
34
00:01:52,896 --> 00:01:53,408
Function
35
00:01:53,920 --> 00:01:56,224
What we done is actually created a
36
00:01:56,736 --> 00:01:59,552
Variable inside of a function
37
00:02:00,320 --> 00:02:02,368
So this new player variable
38
00:02:02,624 --> 00:02:03,904
We just created it
39
00:02:04,416 --> 00:02:10,560
Reference it below whenever we want we can do this at any time because a new player diablo
40
00:02:12,096 --> 00:02:13,632
Equals in
41
00:02:13,888 --> 00:02:19,264
New player that transformed opposition equals new
42
00:02:19,520 --> 00:02:25,408
Hector 30413 position into the zero position in another why we want to do that but
43
00:02:25,664 --> 00:02:27,968
We could reference new player over here
44
00:02:28,224 --> 00:02:28,736
Ok
45
00:02:28,992 --> 00:02:30,272
Here's the problem
46
00:02:30,528 --> 00:02:33,088
What this is this is a local variable
47
00:02:33,344 --> 00:02:35,136
And it's local to this function
48
00:02:35,904 --> 00:02:38,208
So it because it inside of this function
49
00:02:38,464 --> 00:02:44,608
I can actually reference anywhere else I can't reference it in the update so I can say new player
50
00:02:44,864 --> 00:02:45,376
Dart
51
00:02:45,888 --> 00:02:47,680
Coinseed like it just screwed it up
52
00:02:48,192 --> 00:02:50,240
It doesn't exist inside of the update
53
00:02:51,008 --> 00:02:53,824
The reason why most your variables should be declared
54
00:02:54,080 --> 00:02:57,920
Outside of your functions is so that those functions can use them
55
00:02:58,432 --> 00:03:04,576
So because these functions are born outside of the start function outside of the update function in outside
56
00:03:04,832 --> 00:03:05,600
Dysfunction
57
00:03:05,856 --> 00:03:08,416
Is that we can reference these wherever we want
58
00:03:09,184 --> 00:03:11,744
So what we can do here is take this
59
00:03:14,304 --> 00:03:15,072
Delete it
60
00:03:15,584 --> 00:03:16,864
Pasted up here
61
00:03:17,376 --> 00:03:20,704
The problem is you can actually use gameobject that find
62
00:03:20,960 --> 00:03:26,848
Outside of a function rate so we actually can just go new player is new player will it delete that
63
00:03:27,104 --> 00:03:29,664
So we prayed in a new player variable
64
00:03:30,176 --> 00:03:32,480
And it's of the class new player
65
00:03:33,504 --> 00:03:35,808
Pain in side of the start we can actually find it
66
00:03:36,064 --> 00:03:37,600
So new player
67
00:03:37,856 --> 00:03:38,880
Equals
68
00:03:39,904 --> 00:03:42,720
Find new player that get component new player
69
00:03:43,744 --> 00:03:44,512
Now
70
00:03:46,560 --> 00:03:48,352
Remove that really quickly on you that
71
00:03:49,376 --> 00:03:51,168
The animal is well here
72
00:03:51,680 --> 00:03:54,496
So now we can reference new player all over the place
73
00:03:55,008 --> 00:03:57,568
Reference the inside of the update
74
00:03:59,360 --> 00:04:00,896
We need to have a semicolon here
75
00:04:01,152 --> 00:04:01,920
Errigal
76
00:04:02,176 --> 00:04:04,224
Leaving reference it inside of the update
77
00:04:05,504 --> 00:04:06,784
New player
78
00:04:07,040 --> 00:04:13,184
The notice now we can do we can change new player that ammo and we can make it 1000 if we went inside of the up to
79
00:04:13,440 --> 00:04:15,744
Sunshine wicked change the players
80
00:04:16,256 --> 00:04:18,559
Coins if you want to coins collected
81
00:04:19,071 --> 00:04:20,095
Equals 9
82
00:04:20,351 --> 00:04:25,727
Change it inside of the update function and we also change inside of the ontriggerenter function
83
00:04:25,983 --> 00:04:30,079
We can use this new player reference all over the place
84
00:04:30,335 --> 00:04:32,127
Inside of a collectible script
85
00:04:32,639 --> 00:04:33,919
As a recap guys
86
00:04:34,175 --> 00:04:40,319
You're trying to avoid redundancy and that is using lines of code over
87
00:04:40,575 --> 00:04:42,111
Over again that are identical
88
00:04:42,879 --> 00:04:43,391
The Look
89
00:04:44,927 --> 00:04:46,207
We created a variable
90
00:04:47,487 --> 00:04:53,631
In it's not a bully and it's not integers on a float in this case this variable is a
91
00:04:53,887 --> 00:04:54,399
Glass
92
00:04:54,655 --> 00:04:55,423
New player
93
00:04:56,447 --> 00:04:58,495
Today's one single line of code
94
00:04:58,751 --> 00:05:03,871
Doesn't allow unity to actually know which new player class with referencing
95
00:05:04,383 --> 00:05:05,151
Well
96
00:05:05,407 --> 00:05:08,479
We're actually referencing the one on the new player
97
00:05:08,991 --> 00:05:10,015
So that's why
98
00:05:10,527 --> 00:05:13,599
When we start the game number when the start function here
99
00:05:14,111 --> 00:05:15,647
The moment we start the game
100
00:05:16,159 --> 00:05:19,231
Immediately we want the new player variable here
101
00:05:19,743 --> 00:05:23,071
To find the component that were actually trying to reference
102
00:05:23,839 --> 00:05:26,399
So it's going to say new player equals
103
00:05:26,655 --> 00:05:29,983
A magical find new player so I can find the game object
104
00:05:30,495 --> 00:05:32,543
And then I cannot find the component
105
00:05:32,799 --> 00:05:33,567
New player
106
00:05:34,079 --> 00:05:36,895
Now you need a nose that's the one
107
00:05:37,663 --> 00:05:38,943
That we want to reference
108
00:05:39,455 --> 00:05:42,015
No because we found that component
109
00:05:43,295 --> 00:05:44,575
We now know
110
00:05:45,343 --> 00:05:48,927
Any time we use this variable it equals this
111
00:05:49,695 --> 00:05:51,743
So we can use it all over the place
112
00:05:52,255 --> 00:05:55,327
The moment our character touches or triggers into
113
00:05:55,583 --> 00:05:56,607
This collectible
114
00:05:57,631 --> 00:06:00,447
It's going to be right the coins collected up one
115
00:06:01,215 --> 00:06:05,823
Is also going to fire the update you a function that's inside of new player
116
00:06:07,359 --> 00:06:12,735
Instead of writing this over and over and over again we can just have a reference a single reference to it
117
00:06:12,991 --> 00:06:15,039
And use that single word
118
00:06:15,295 --> 00:06:16,575
Over and over again
119
00:06:17,343 --> 00:06:18,879
This it makes sense to you
120
00:06:19,135 --> 00:06:23,999
We're gonna keep going and it's going to slowly start making sense more and more
121
00:06:24,511 --> 00:06:27,071
As we use this as often as we can
122
00:06:27,327 --> 00:06:30,911
Again anytime you see a line of code that identical
123
00:06:31,423 --> 00:06:34,751
You really want one reference to that line of code if you can
124
00:06:35,007 --> 00:06:41,151
So in conclusion guys if you ever are using a line of code over and over again so in this case
125
00:06:41,407 --> 00:06:43,967
It was this line here we were using that multiple times
126
00:06:44,735 --> 00:06:50,879
Accuracy that that's called redundancy and you really don't want to do there it makes it painful for you makes
127
00:06:51,135 --> 00:06:54,975
Enabled for your team because you've got a cold it's a written over and over and over again
128
00:06:55,487 --> 00:07:01,119
Also slows down unity every time you find a game object and then find a component
129
00:07:01,887 --> 00:07:04,191
It's actually slowing down unity just a little bit
130
00:07:05,215 --> 00:07:07,775
So if you make a single reference right here
131
00:07:08,031 --> 00:07:11,359
When we fire the start function the moment we start unity
132
00:07:11,615 --> 00:07:14,431
Unity nose immediately what new player is
133
00:07:15,455 --> 00:07:17,503
Now I can actually use their variable
134
00:07:18,527 --> 00:07:20,575
To collect coins and update the UI
135
00:07:21,343 --> 00:07:24,159
Save it out and just checking to see if it works
136
00:07:24,415 --> 00:07:29,791
When I get a worry about this morning's here guys you going to see a lot of warnings when you're making your game
137
00:07:30,047 --> 00:07:33,119
It's good to try and get rid of them but I'm just gonna clear I'm out for now
138
00:07:33,887 --> 00:07:35,423
Alright so looks like we have
139
00:07:36,959 --> 00:07:39,007
Strange figure out what this area is
140
00:07:39,263 --> 00:07:42,847
Is object reference not set to an instance of an object
141
00:07:43,359 --> 00:07:46,687
What is the price of an easy solution with double click on it and see what happens
142
00:07:47,455 --> 00:07:50,783
Ok looks like it can't find new player
143
00:07:51,551 --> 00:07:56,671
Looks like we've got a little bit here about in the future how you can avoid these kinds of mistakes
144
00:07:57,183 --> 00:08:02,303
Game object that finds new player will remember we don't actually have a game object called new player
145
00:08:02,559 --> 00:08:04,095
Gameobject has just called
146
00:08:04,607 --> 00:08:05,119
Player
147
00:08:06,399 --> 00:08:10,495
As you can see it unity can't find that game object
148
00:08:10,751 --> 00:08:11,519
It's going to tell you
149
00:08:12,031 --> 00:08:14,847
So we need to do is make this player
150
00:08:15,615 --> 00:08:16,383
It said
151
00:08:16,895 --> 00:08:18,431
Jump back in the Unity
152
00:08:19,199 --> 00:08:22,271
And let it play in see how it looks
153
00:08:24,575 --> 00:08:27,391
Alright it's like everything is working
154
00:08:29,183 --> 00:08:29,951
Awesome
155
00:08:33,535 --> 00:08:36,863
That guy is another way that we can tell unity
156
00:08:37,119 --> 00:08:38,655
Who new player is
157
00:08:39,167 --> 00:08:41,215
And also which component with referencing
158
00:08:41,471 --> 00:08:44,287
We can actually remove this completely
159
00:08:45,311 --> 00:08:48,127
So all we have is this new player
160
00:08:48,383 --> 00:08:50,943
Variable that doesn't actually reference anything
161
00:08:51,199 --> 00:08:53,503
Holidays is Ava type new player
162
00:08:54,527 --> 00:08:56,063
Have you got back in the Unity
163
00:08:56,319 --> 00:08:58,367
Universe we don't get any areas around
164
00:08:58,879 --> 00:09:00,927
That's because unity is thinking well
165
00:09:01,439 --> 00:09:04,255
Maybe Thomas is going to tell me in a different way
166
00:09:05,023 --> 00:09:06,815
How exactly could we do that
167
00:09:07,583 --> 00:09:12,447
Go ahead and select this little coin here
168
00:09:12,959 --> 00:09:13,983
Like this coin
169
00:09:14,495 --> 00:09:20,127
And you noticed that the new player variable isn't showing up inside of the component
170
00:09:20,895 --> 00:09:22,943
What's open up the collectible scrapyard
171
00:09:23,199 --> 00:09:25,247
What's go ahead in serialise this
172
00:09:26,271 --> 00:09:27,807
Serializefield
173
00:09:28,575 --> 00:09:30,111
Ennis pizza ring make it private
174
00:09:31,391 --> 00:09:32,671
Go back in the unity here
175
00:09:33,695 --> 00:09:34,719
And you can see
176
00:09:34,975 --> 00:09:38,815
The Honor collectible script now we have a new player
177
00:09:39,327 --> 00:09:39,839
Ok
178
00:09:41,119 --> 00:09:47,263
So now we can see the new player well you can see that it's set to 9 it doesn't know which new player were actually Reverend
179
00:09:48,543 --> 00:09:51,103
Well we can actually while it's selected
180
00:09:51,359 --> 00:09:53,151
Just drag the player
181
00:09:53,919 --> 00:09:56,735
Over 2 this field is automatically going to
182
00:09:56,991 --> 00:09:57,759
Find
183
00:10:00,345 --> 00:10:02,632
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
184
00:10:02,634 --> 00:10:01,343
So
185
00:10:01,599 --> 00:10:02,879
If we had play here
186
00:10:04,671 --> 00:10:05,695
You noticed that
187
00:10:06,207 --> 00:10:07,487
This one here
188
00:10:08,511 --> 00:10:10,559
Actually knows who the new player is
189
00:10:10,815 --> 00:10:14,911
So we can actually collect it you'll fire that update you a function in there we go
190
00:10:15,167 --> 00:10:16,191
These
191
00:10:16,959 --> 00:10:19,263
They don't know you can see we have an error
192
00:10:20,287 --> 00:10:22,847
I don't know because we didn't actually
193
00:10:24,639 --> 00:10:25,407
Rag
194
00:10:26,687 --> 00:10:28,991
A player over to this field here
195
00:10:29,503 --> 00:10:31,295
So that is why
196
00:10:31,551 --> 00:10:32,575
In our case
197
00:10:34,879 --> 00:10:36,159
We actually white
198
00:10:37,183 --> 00:10:38,463
To include
199
00:10:38,719 --> 00:10:39,487
This
200
00:10:40,255 --> 00:10:42,303
For every single collectible script
201
00:10:43,327 --> 00:10:46,655
Sometimes you gonna want to actually find it in The Script
202
00:10:47,167 --> 00:10:47,935
Are the times
203
00:10:48,703 --> 00:10:54,335
Especially if you only using a gameobject 1 so for example if I was referencing something from the player script
204
00:10:55,103 --> 00:10:57,663
Actually just drag coins text over here
205
00:10:59,199 --> 00:11:02,271
Because I'm going to have one player in the entire game
206
00:11:03,295 --> 00:11:05,343
Dragging the coins text over here
207
00:11:05,599 --> 00:11:07,135
Actually makes a lot of sense
208
00:11:07,647 --> 00:11:09,439
So we going to have a new player script
209
00:11:10,975 --> 00:11:12,511
We can actually just get rid of this
210
00:11:15,583 --> 00:11:16,351
Now
211
00:11:18,399 --> 00:11:20,191
Is there a finding that in the strip
212
00:11:21,727 --> 00:11:24,287
Just told unity with a simple drag-and-drop
213
00:11:25,311 --> 00:11:27,359
Where are coming to the Pony actually is
214
00:11:28,127 --> 00:11:32,479
If this doesn't make sense guys we're gonna be doing this a lot in these tutorials
215
00:11:32,735 --> 00:11:35,039
So don't stress too much I just keep going
216
00:11:35,295 --> 00:11:41,439
Hopefully you'll understand when you want actually read out the script and maybe when you want to drag and drop a good rule of thumb
217
00:11:41,695 --> 00:11:46,815
If multiple objects say enemies enemies hundreds of enemies
218
00:11:47,327 --> 00:11:49,375
Are referencing one game object
219
00:11:49,887 --> 00:11:51,167
Do you want to do that in the Script
220
00:11:51,423 --> 00:11:52,959
OK mate that's fine
221
00:11:53,215 --> 00:11:54,239
Getcomponent
222
00:11:55,007 --> 00:11:59,359
If on the other hand a single game object for example this player
223
00:11:59,615 --> 00:12:03,967
Is referencing another single game object so in this case
224
00:12:04,223 --> 00:12:05,759
The coins UI element
225
00:12:06,015 --> 00:12:08,319
I see no reason why not just drag it over
226
00:12:08,575 --> 00:12:09,599
Infidelity
17281
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.