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
Alright so we can create probably one of my favourite
2
00:00:13,056 --> 00:00:16,640
Of platformers and that is just collectible coins
3
00:00:16,896 --> 00:00:23,040
Tesco head in jump back into Photoshop or we could have double click on level one here this is our p.m.
4
00:00:23,296 --> 00:00:23,808
Defile
5
00:00:24,576 --> 00:00:26,368
Is it open in Photoshop for us
6
00:00:26,880 --> 00:00:33,024
As you can see we have our ground we have a player in because it is create a coin now if you get destroyed
7
00:00:33,280 --> 00:00:36,096
See where your ground is in
8
00:00:36,352 --> 00:00:38,656
White background
9
00:00:38,912 --> 00:00:42,240
Go ahead and select your background here and click on this lock
10
00:00:43,264 --> 00:00:48,128
Allow us to actually change the background layer that came by default
11
00:00:48,384 --> 00:00:49,664
With this Photoshop file
12
00:00:50,432 --> 00:00:51,968
I'm just going to go to image
13
00:00:52,992 --> 00:00:53,760
Adjustments
14
00:00:54,016 --> 00:00:56,320
And how about just hue saturation
15
00:00:57,088 --> 00:01:00,781
This allows especially just like this as well so we can just make this little prayer
16
00:01:00,783 --> 00:01:03,131
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
17
00:01:03,132 --> 00:01:02,464
Jericho
18
00:01:02,720 --> 00:01:07,072
This is our background layer let's be sure it's the right name so let's call it background
19
00:01:08,096 --> 00:01:11,936
And I like to put the word reference in parentheses
20
00:01:12,192 --> 00:01:18,336
Well I know I'm not actually going to use this layer in the actual game but it's good to have in my Photoshop file
21
00:01:18,592 --> 00:01:19,616
Presenter
22
00:01:20,128 --> 00:01:26,272
Ok now let's go ahead and create a coin does using a rectangle marketo and click and hold
23
00:01:26,528 --> 00:01:28,832
Tuesday elliptical marquee tool
24
00:01:29,600 --> 00:01:32,416
A hold ship that's going to allow me to create
25
00:01:32,672 --> 00:01:38,048
A perfect circle and I'm going to click and drag and I think that looks great
26
00:01:38,816 --> 00:01:40,096
Now going to fill.in
27
00:01:40,864 --> 00:01:42,912
We want this to be a white swatch
28
00:01:43,168 --> 00:01:44,192
We can actually just
29
00:01:44,448 --> 00:01:47,008
In Dragon 2 white
30
00:01:47,264 --> 00:01:49,568
Or we can actually just click this
31
00:01:49,824 --> 00:01:51,360
Invert button here
32
00:01:52,128 --> 00:01:58,272
Convert are to swatches watches we have on hand currently stuff I want to Black to be
33
00:01:58,528 --> 00:02:03,648
Say what time does pink and do that click ok and I get a switch between the two
34
00:02:04,672 --> 00:02:06,208
Fortnite keeps winning the White
35
00:02:06,976 --> 00:02:09,792
Fill.in press ctrl-d to deselect
36
00:02:10,048 --> 00:02:13,632
And now we have a coin to win in that coin
37
00:02:13,888 --> 00:02:14,912
And then save
38
00:02:15,936 --> 00:02:17,728
How is your back into unity
39
00:02:19,520 --> 00:02:22,848
And you'll see that our coin is now a sprout
40
00:02:23,360 --> 00:02:24,128
Imported
41
00:02:24,384 --> 00:02:25,920
Into our project folder
42
00:02:26,688 --> 00:02:28,224
Here is a coin sprite
43
00:02:28,992 --> 00:02:31,296
In your head in drag by in the scene
44
00:02:31,808 --> 00:02:33,088
About there
45
00:02:33,600 --> 00:02:38,464
It must make sure we put it in the right layer so I know that layer one is where all of my
46
00:02:38,720 --> 00:02:39,744
Rounders
47
00:02:40,256 --> 00:02:44,096
Best primary one of the coin as well that's drag there and put it right here
48
00:02:45,632 --> 00:02:46,144
Great
49
00:02:46,400 --> 00:02:49,216
Might as well make the coin a prefab
50
00:02:49,472 --> 00:02:49,984
Because
51
00:02:50,240 --> 00:02:53,056
Honestly we're going to be collecting a lot of coins in the scheme
52
00:02:53,312 --> 00:02:56,896
So anything you're reusing over and over again
53
00:02:57,152 --> 00:02:58,944
Always create a prefab
54
00:02:59,200 --> 00:03:01,504
This is dragon coin the pre 50
55
00:03:02,016 --> 00:03:04,832
And was go ahead in hip play and see how it looks
56
00:03:09,184 --> 00:03:09,696
Awesome
57
00:03:10,208 --> 00:03:13,024
Obviously I'm not collecting the coin but
58
00:03:13,792 --> 00:03:15,328
And all looks pretty good
59
00:03:16,864 --> 00:03:19,168
So how do we collect this coin
60
00:03:19,936 --> 00:03:23,008
Create a new script in when I get a call it coin
61
00:03:23,264 --> 00:03:25,312
Hexagon collectible
62
00:03:25,568 --> 00:03:26,336
Why is that
63
00:03:26,848 --> 00:03:28,384
When you creating a script
64
00:03:28,640 --> 00:03:31,200
You want to make it as broad as possible
65
00:03:31,712 --> 00:03:36,064
The reason why is you why use as little new scripts as possible
66
00:03:36,576 --> 00:03:38,368
So we're gonna call it a collectible
67
00:03:38,624 --> 00:03:44,768
That's because coins health emanation or keys are other collectible items
68
00:03:45,024 --> 00:03:47,840
They are pretty much behave the same don't they
69
00:03:48,096 --> 00:03:50,912
Just adjusting different inventory items
70
00:03:52,192 --> 00:03:53,728
What we're going to do is create a new script
71
00:03:55,520 --> 00:03:56,800
Make sure you select
72
00:03:57,312 --> 00:04:01,408
Inside the scripts folder before you create a new c sharp script
73
00:04:01,920 --> 00:04:02,944
How much is call this
74
00:04:03,200 --> 00:04:03,968
Collectible
75
00:04:04,992 --> 00:04:08,320
And will do is just drag the script on to a coin
76
00:04:09,088 --> 00:04:14,208
You're obviously do anything because we have actually written anything but
77
00:04:14,720 --> 00:04:16,000
Now we can double click
78
00:04:16,256 --> 00:04:18,303
Open it up in Visual Studio
79
00:04:19,583 --> 00:04:21,631
To the first thing we want to do with this
80
00:04:21,887 --> 00:04:23,167
Collectible script
81
00:04:23,679 --> 00:04:29,823
Is actually identify whether is a collectible item oran.mor item or
82
00:04:30,079 --> 00:04:31,615
Coin item or just a
83
00:04:31,871 --> 00:04:33,151
Inventory item
84
00:04:33,663 --> 00:04:37,503
So what we can do is if you guys remember we have bullions rape
85
00:04:38,271 --> 00:04:40,575
Wiki create a new private bullion
86
00:04:40,831 --> 00:04:42,623
Navigate say is
87
00:04:42,879 --> 00:04:43,647
Coin
88
00:04:44,671 --> 00:04:45,951
= boss
89
00:04:46,719 --> 00:04:48,255
Or just leave it at
90
00:04:49,023 --> 00:04:51,071
This in by default it will be false
91
00:04:52,095 --> 00:04:55,935
So that's one way of doing it so let's go ahead and do that we can have
92
00:04:56,959 --> 00:05:02,079
The sea for bullying so we can have a coin we could have a health
93
00:05:02,335 --> 00:05:03,103
We could have
94
00:05:04,127 --> 00:05:04,895
Is
95
00:05:05,663 --> 00:05:06,431
Emo
96
00:05:06,943 --> 00:05:07,711
We could have
97
00:05:08,735 --> 00:05:10,783
Is inventory
98
00:05:11,039 --> 00:05:11,551
Adam
99
00:05:11,807 --> 00:05:12,319
Ok
100
00:05:13,599 --> 00:05:15,391
What is this look like inside of Unity
101
00:05:17,695 --> 00:05:19,231
Let's go to a coin here
102
00:05:20,767 --> 00:05:21,791
Soccer coin
103
00:05:22,559 --> 00:05:24,351
What makes it not say anything
104
00:05:25,375 --> 00:05:26,399
Why is that
105
00:05:26,911 --> 00:05:28,447
Are you priority guest it
106
00:05:28,703 --> 00:05:32,287
The reason is because these are all private variables meaning
107
00:05:32,543 --> 00:05:36,639
Even private to the unity editor so we can't even see them
108
00:05:37,151 --> 00:05:38,943
In our inspector
109
00:05:39,199 --> 00:05:42,783
How do you solve that won't you priority guessed it we're going to do
110
00:05:43,551 --> 00:05:45,599
Serialise field
111
00:05:46,879 --> 00:05:50,463
Copy that and paste it on each one
112
00:05:50,975 --> 00:05:56,351
Again you can do either public variables they show up in the inspector and you can edit them inside of Unity
113
00:05:57,119 --> 00:05:57,631
Or
114
00:05:57,887 --> 00:05:59,679
You just serialise a private
115
00:05:59,935 --> 00:06:00,703
Variable
116
00:06:00,959 --> 00:06:02,751
Is going to campus the same thing
117
00:06:03,775 --> 00:06:05,311
So here are our
118
00:06:05,823 --> 00:06:06,591
Or
119
00:06:07,103 --> 00:06:07,871
Billions
120
00:06:08,383 --> 00:06:09,151
So
121
00:06:09,407 --> 00:06:10,175
We could be
122
00:06:10,431 --> 00:06:12,991
Is coin and that means pay I'm a coin
123
00:06:14,527 --> 00:06:16,319
Is health that means I'm health
124
00:06:16,575 --> 00:06:18,111
Is a multimedia memo
125
00:06:18,367 --> 00:06:21,439
Or is inventory item that means I'm an inventory item
126
00:06:22,207 --> 00:06:28,351
So we're not going to make it this messy some of you who might understand code a little bit better than I do we'll be looking at this
127
00:06:28,607 --> 00:06:34,751
Thomas there's a better way to do this and there is a make sure you in just a second when I want to drive my point home
128
00:06:35,519 --> 00:06:39,359
Is allows us to have all different types of collectibles
129
00:06:39,615 --> 00:06:41,407
Goddess using one script
130
00:06:43,199 --> 00:06:44,735
What creates a
131
00:06:44,991 --> 00:06:46,527
Way to check
132
00:06:46,783 --> 00:06:50,111
And do something based on each type of item
133
00:06:50,367 --> 00:06:53,439
Well we got to do is just do some if conditionals
134
00:06:53,695 --> 00:06:54,975
So what we can do is
135
00:06:55,487 --> 00:06:57,279
If I'm a coin
136
00:06:57,535 --> 00:06:58,559
Let's say
137
00:06:59,071 --> 00:07:00,607
Print to the console
138
00:07:01,887 --> 00:07:02,655
I'm a coin
139
00:07:03,935 --> 00:07:04,447
Ok
140
00:07:05,983 --> 00:07:08,287
Well how do we write there in actual code
141
00:07:08,799 --> 00:07:09,567
Yes
142
00:07:10,335 --> 00:07:11,615
Is coin
143
00:07:14,431 --> 00:07:15,711
Equals equals true
144
00:07:15,967 --> 00:07:18,527
Or a quicker way to write this is just
145
00:07:18,783 --> 00:07:20,063
If is going
146
00:07:22,623 --> 00:07:24,671
Then debug.log
147
00:07:25,183 --> 00:07:26,719
I'm a coin
148
00:07:29,279 --> 00:07:30,303
Set alarm
149
00:07:30,559 --> 00:07:31,839
And jump in unity
150
00:07:33,887 --> 00:07:36,959
And let's sitar is going to true
151
00:07:37,983 --> 00:07:40,031
On our coin game object
152
00:07:40,287 --> 00:07:42,079
Play and see what happens
153
00:07:45,663 --> 00:07:48,223
I'm a coin is immediately printed
154
00:07:48,735 --> 00:07:50,271
Do they cancel because
155
00:07:51,295 --> 00:07:52,319
In the start
156
00:07:52,575 --> 00:07:55,135
We have this condition if is coin
157
00:07:55,903 --> 00:07:57,695
Ibo.org I'm a coin
158
00:07:58,207 --> 00:08:02,047
So what if I wanted to check if it's health instead of a coin
159
00:08:02,559 --> 00:08:08,703
What serial code would be something like if I'm not a coin and instead
160
00:08:08,959 --> 00:08:09,471
Health
161
00:08:10,495 --> 00:08:12,287
Then print to the console
162
00:08:13,311 --> 00:08:14,079
I'm
163
00:08:14,335 --> 00:08:17,407
Not a coin I'm actually
164
00:08:18,431 --> 00:08:20,735
How would we write this in actual code
165
00:08:21,247 --> 00:08:21,759
Well
166
00:08:22,271 --> 00:08:24,319
Yes you something called else
167
00:08:25,343 --> 00:08:28,159
So if I'm not a coin then I must be
168
00:08:28,671 --> 00:08:31,999
Something else so in this case let's just say I'm
169
00:08:33,535 --> 00:08:34,303
Health
170
00:08:35,583 --> 00:08:36,607
Say that out
171
00:08:38,143 --> 00:08:42,495
So if I die select is coin and I said that false
172
00:08:44,031 --> 00:08:45,055
Play
173
00:08:47,359 --> 00:08:48,895
Looks like it says I'm health
174
00:08:49,151 --> 00:08:50,943
That's not necessarily true is it
175
00:08:51,711 --> 00:08:56,319
Just because is coin is set to false doesn't mean that it's a help collectible
176
00:08:57,087 --> 00:08:59,391
The way that we would do this is actually use
177
00:08:59,647 --> 00:09:00,159
Else
178
00:09:00,415 --> 00:09:00,927
If
179
00:09:01,439 --> 00:09:02,719
Is health
180
00:09:03,487 --> 00:09:08,095
Then I'm health well we can actually just keep going down the line
181
00:09:09,631 --> 00:09:10,911
Is anal
182
00:09:12,447 --> 00:09:17,055
NN1 more after this and then debug.log
183
00:09:18,079 --> 00:09:19,359
I'm Emma
184
00:09:20,639 --> 00:09:25,503
NN1 more we actually don't need it to be else if it just beat else
185
00:09:25,759 --> 00:09:28,575
So if all of these turned out to be false
186
00:09:29,087 --> 00:09:33,951
Then by the fault it's just an inventory item so debug.log
187
00:09:35,231 --> 00:09:37,023
I'm in inventory
188
00:09:37,279 --> 00:09:37,791
Adam
189
00:09:40,607 --> 00:09:44,447
Alright in what time means we actually don't even need this bullying
190
00:09:44,703 --> 00:09:45,983
We can just delete that
191
00:09:46,239 --> 00:09:47,775
We have three types
192
00:09:48,031 --> 00:09:50,079
If all three of those types of false
193
00:09:50,335 --> 00:09:52,383
Initiative generic inventory item
194
00:09:53,663 --> 00:09:57,503
Save that we can get rid of this pseudocode comment here
195
00:09:58,271 --> 00:09:59,295
David out
196
00:10:00,345 --> 00:10:02,248
Subtitled by
-♪ online-courses.club ♪-
We compress knowledge for you!
https://t.me/joinchat/ailxpXoW3JVjYzQ1
197
00:10:02,250 --> 00:10:05,439
When was checking to see if this works but sorted out by just testing is coming so it's true
198
00:10:05,951 --> 00:10:06,719
Play
199
00:10:07,231 --> 00:10:09,791
Pacific debugs to the console window
200
00:10:10,303 --> 00:10:12,351
Does it's great I am a coin
201
00:10:12,863 --> 00:10:15,423
Someone's I deselect it and then do is hell
202
00:10:16,191 --> 00:10:17,727
Nothing's getting printed to the window
203
00:10:17,983 --> 00:10:23,615
Why is that just 3 sure guys remember it's happening inside of a start function
204
00:10:24,127 --> 00:10:30,271
So we actually have to restart the game so let's set is coined false and an is health
205
00:10:30,527 --> 00:10:32,063
Is true and then apply again
206
00:10:33,855 --> 00:10:34,623
What's great
207
00:10:35,135 --> 00:10:36,415
Tickets I'm health
208
00:10:36,671 --> 00:10:38,463
How much is test is amo
209
00:10:44,095 --> 00:10:44,607
Right
210
00:10:45,119 --> 00:10:46,143
I'm Emma
211
00:10:46,911 --> 00:10:47,935
What if I just
212
00:10:48,191 --> 00:10:49,727
Take care off completely
213
00:10:52,543 --> 00:10:54,335
Looks like I'm in inventory item
214
00:10:54,847 --> 00:10:57,663
Is being printed to the console and that's exactly right
215
00:10:58,175 --> 00:11:03,039
So basically are collectible script is going to allow us to do certain properties
216
00:11:04,319 --> 00:11:05,087
Based on
217
00:11:05,855 --> 00:11:07,135
Is bullying here
218
00:11:08,415 --> 00:11:12,255
Now believe it or not there is actually a much cleaner way
219
00:11:12,767 --> 00:11:15,071
To set up these three variables
220
00:11:15,839 --> 00:11:17,375
Look at the inspector here
221
00:11:18,655 --> 00:11:23,519
If we could magically change this inspector would be a much cleaner way to do this
222
00:11:24,031 --> 00:11:27,359
I think a dropdown menu where you can only select one
223
00:11:27,615 --> 00:11:30,175
Would actually be much more effective
224
00:11:30,431 --> 00:11:32,223
Just be a cleaner way to do it
225
00:11:32,991 --> 00:11:36,575
So what we can do is actually create a new variable type
226
00:11:37,087 --> 00:11:42,463
Night necessarily a bully and although it's kind of similar to a bullying or maybe it's a combination
227
00:11:42,719 --> 00:11:45,279
A brilliant is perhaps a good way to think about it
228
00:11:45,791 --> 00:11:46,559
It's cold
229
00:11:46,815 --> 00:11:47,839
In eNom
230
00:11:48,351 --> 00:11:49,887
What the heck is an email
231
00:11:50,399 --> 00:11:55,007
Have you ever confused about what a certain variable type is just Google it
232
00:11:55,263 --> 00:11:56,543
In immunity
233
00:11:57,823 --> 00:12:01,151
Ok let's take a look what is an Anam
234
00:12:01,407 --> 00:12:03,199
Unity editor stuck on that
235
00:12:04,735 --> 00:12:10,879
Looks like we have a reply here with 17 upvotes on a answers that you needed that calm
236
00:12:11,135 --> 00:12:13,695
What does says my name is a keyword
237
00:12:13,951 --> 00:12:18,815
That allows you to declare an enumeration is in a numeration
238
00:12:19,327 --> 00:12:22,143
Innovation is a set of names for values
239
00:12:22,399 --> 00:12:23,167
Example
240
00:12:23,423 --> 00:12:26,751
Difficulty is easy normal in heart
241
00:12:27,263 --> 00:12:29,567
Ok so maybe that's a drop down menu
242
00:12:30,079 --> 00:12:34,687
Does Go-Ahead in declare this inside of r script
243
00:12:35,199 --> 00:12:40,575
So we're going to comment Out All Over bullying here in the way you do that is forward slash star
244
00:12:41,599 --> 00:12:43,903
Star forward slash
245
00:12:44,415 --> 00:12:47,231
And now we have a different way of commenting in
246
00:12:47,487 --> 00:12:48,767
Visual Studio
247
00:12:49,023 --> 00:12:51,327
Just keep this just in case we need it
248
00:12:51,583 --> 00:12:57,727
Anytime is a script that you might want to save but you know you don't want it actually doing anything in your current build
249
00:12:57,983 --> 00:12:59,519
Just commented out like that
250
00:13:00,543 --> 00:13:02,847
Does create an enum variable type
251
00:13:03,103 --> 00:13:04,639
Typing eNom
252
00:13:05,407 --> 00:13:06,431
Let's call it
253
00:13:06,687 --> 00:13:07,967
Item type
254
00:13:08,479 --> 00:13:11,295
We were going to declare this is within open bracket
255
00:13:11,551 --> 00:13:12,575
And I'm going to type
256
00:13:12,831 --> 00:13:15,903
Let's see where coin we have health
257
00:13:16,415 --> 00:13:17,183
And then we have
258
00:13:18,719 --> 00:13:21,023
I come in here so we don't go crazy
259
00:13:21,279 --> 00:13:26,399
Is create an item type enum or that's a
260
00:13:26,911 --> 00:13:27,935
Rock down
261
00:13:29,471 --> 00:13:30,239
Ok
262
00:13:30,751 --> 00:13:32,287
Not done just yet
263
00:13:32,543 --> 00:13:35,615
We Created by number we actually declared the variable
264
00:13:35,871 --> 00:13:37,663
So that we can see inside of the inspector
265
00:13:38,175 --> 00:13:40,735
So we're going to do is type serializefield
266
00:13:41,759 --> 00:13:43,551
We know we want to see it in the inspector
267
00:13:43,807 --> 00:13:44,575
Private
268
00:13:44,831 --> 00:13:46,111
Item type
269
00:13:47,135 --> 00:13:48,927
Item type
270
00:13:50,975 --> 00:13:51,743
And that's about it
271
00:13:52,767 --> 00:13:55,583
I know this is a little bit confusing because we're doing it twice
272
00:13:55,839 --> 00:13:58,143
I just know that this is creating the ii-nam
273
00:13:58,655 --> 00:14:04,799
We also need to create a variable that uses that eNom in this case it's called Adam type with a cat
274
00:14:05,055 --> 00:14:05,567
I
275
00:14:06,335 --> 00:14:08,895
We have a new anam called Adam type
276
00:14:09,151 --> 00:14:11,455
That we can use inside of this collectible script
277
00:14:11,711 --> 00:14:15,551
Create a new item type variable and then with a lowercase I
278
00:14:16,063 --> 00:14:17,087
Create a variable
279
00:14:17,855 --> 00:14:23,999
Don't save this year I know that this might be confusing and sometimes you actually have the Google how you declare the
280
00:14:24,255 --> 00:14:26,303
Even I forget sometimes
281
00:14:26,815 --> 00:14:32,959
So if you ever forget has declare in use an enaam just Google it and you'll see the answer at the top of Google
282
00:14:33,215 --> 00:14:35,775
I do it all the time most developers do this as well
283
00:14:36,543 --> 00:14:38,335
Heartless jump in the unity here
284
00:14:40,127 --> 00:14:42,175
Hopefully everything is working
285
00:14:42,431 --> 00:14:43,967
It looks like we have some errors
286
00:14:44,223 --> 00:14:46,271
Privacy errors in your console
287
00:14:46,783 --> 00:14:48,063
You try and hit play
288
00:14:49,343 --> 00:14:55,487
It says all compiler errors have to be fixed before you enter play mode because you nearly can actually
289
00:14:55,743 --> 00:14:58,815
In anything if there's one script that's broken
290
00:14:59,327 --> 00:15:03,679
Like we have a tenner bearers here 3 hours and that's kind of terrifying what's going on
291
00:15:03,935 --> 00:15:04,959
What's double click
292
00:15:06,495 --> 00:15:07,007
Alcohol
293
00:15:07,519 --> 00:15:11,359
Actually takes us inside a Visual Studio and shows us where the errors are
294
00:15:12,127 --> 00:15:13,663
The red zig zag here
295
00:15:13,919 --> 00:15:15,711
That means that is coined
296
00:15:15,967 --> 00:15:16,479
Well
297
00:15:16,735 --> 00:15:22,879
Guess it's just not a variable y is that other over the name is coin does not exist in the current context
298
00:15:23,135 --> 00:15:27,743
No that's because we actually commented out the Declaration of these variables exist anymore
299
00:15:28,255 --> 00:15:29,023
I see
300
00:15:29,535 --> 00:15:34,655
So but actually just comment out all of this is well just for now so we can
301
00:15:34,911 --> 00:15:37,471
Take a look and see how it looks
302
00:15:37,727 --> 00:15:38,751
In unity
303
00:15:39,775 --> 00:15:42,591
Alright so now The Script should be able to compile
304
00:15:43,103 --> 00:15:44,639
Ok great no more hours
305
00:15:45,919 --> 00:15:50,271
Now we can see our collectible script here has an item type variable
306
00:15:51,039 --> 00:15:52,575
And not a drop down menu
307
00:15:52,831 --> 00:15:53,343
Sweet
308
00:15:53,855 --> 00:15:56,159
Coin or we can choose health
309
00:15:56,415 --> 00:15:57,695
Pikachu's ml
310
00:15:57,951 --> 00:15:59,487
I like that
311
00:16:01,023 --> 00:16:03,071
Worcester back in the Visual Studio here
312
00:16:04,351 --> 00:16:07,423
And now it's think about how we could actually check
313
00:16:07,679 --> 00:16:12,031
To see if we've selected coin health or ammo
314
00:16:12,543 --> 00:16:13,823
In the dropdown menu
315
00:16:14,847 --> 00:16:17,407
Just go ahead in uncomment this out
316
00:16:18,431 --> 00:16:23,039
Instead of saying if is coin because we don't really have this bullying anymore
317
00:16:23,295 --> 00:16:24,831
The way we check
318
00:16:25,087 --> 00:16:27,647
What's selected in the dropdown menu is
319
00:16:27,903 --> 00:16:28,415
Yes
320
00:16:28,927 --> 00:16:30,207
Item type
321
00:16:30,719 --> 00:16:31,487
Equals
322
00:16:32,511 --> 00:16:36,095
The item type of be created here that
323
00:16:36,863 --> 00:16:38,911
Coin ok cool
324
00:16:39,423 --> 00:16:42,751
Rod SL safe item type
325
00:16:43,007 --> 00:16:44,031
Equals equals
326
00:16:44,543 --> 00:16:47,359
Item type that a look
327
00:16:47,871 --> 00:16:50,431
It's suggesting that three different item types for us
328
00:16:50,943 --> 00:16:53,759
Well let's see here we can double click health
329
00:16:54,015 --> 00:16:54,527
Raped
330
00:16:54,783 --> 00:16:56,063
One more time
331
00:16:56,319 --> 00:16:57,855
If I am type
332
00:16:58,111 --> 00:17:00,927
Equals equals item type dot
333
00:17:01,695 --> 00:17:02,207
Emma
334
00:17:03,231 --> 00:17:03,999
Awesome
335
00:17:04,767 --> 00:17:10,911
Toyota thinking it is a lot of C Sharp and syntax that I'm going to have them memorise and understand
336
00:17:11,423 --> 00:17:17,311
Thomas understands all his stuff and he doesn't actually need to reference anything and that's just not true guys
337
00:17:17,567 --> 00:17:23,711
I promise you when I wrote this code originally had a reference things on unities website
338
00:17:23,967 --> 00:17:26,527
How to Google how to declare an enum type
339
00:17:27,039 --> 00:17:30,367
How to check if an email type is in your condition
340
00:17:30,623 --> 00:17:36,767
Those kind of questions are always being Googled in fact I would argue Google is open all
341
00:17:37,023 --> 00:17:40,607
Time on another monitor for pretty much every developer out there
342
00:17:41,375 --> 00:17:47,519
Developers out there who will look at this tutorial and say if Thomas doesn't even know how to clear my number
343
00:17:47,775 --> 00:17:49,055
Then he doesn't wanna make games
344
00:17:49,311 --> 00:17:53,919
And it's just not true guys have made two games and release them on pretty much every platform
345
00:17:54,431 --> 00:18:00,575
It's important to note that you should not be signed into not using Google Google is your friend
346
00:18:00,831 --> 00:18:04,159
And honestly you don't have to memorise everything about code
347
00:18:04,671 --> 00:18:05,183
Tell
348
00:18:05,439 --> 00:18:07,743
What's happened to Unity here after saving
349
00:18:09,023 --> 00:18:10,559
See how everything works
350
00:18:12,607 --> 00:18:14,655
Looks like we have some alerts here
351
00:18:14,911 --> 00:18:21,055
Mcanally worry about these you guys are get alerts all the time they're kind of just part for the course I'm in clueless
352
00:18:21,311 --> 00:18:23,359
If we can address those later
353
00:18:24,127 --> 00:18:26,175
Take a look at our drop down menu here
354
00:18:27,199 --> 00:18:32,319
Great surveyselect MOT and I have play it should show up in the console window
355
00:18:33,343 --> 00:18:34,367
I'm emo
356
00:18:34,623 --> 00:18:35,391
Sweet
357
00:18:35,647 --> 00:18:40,511
Looks like we're able to check what item types are in the drop down menu
358
00:18:40,767 --> 00:18:43,071
And then do something based on their condition
359
00:18:43,327 --> 00:18:45,631
That's exactly what we want to do some really cool
360
00:18:46,143 --> 00:18:50,751
Ok we'll go ahead and get rid of this comment without portion Here We Don't Need That Anymore
361
00:18:53,567 --> 00:18:54,847
Save it
362
00:18:56,383 --> 00:18:59,455
So we have a basic script written
363
00:18:59,711 --> 00:19:00,735
Are collectible
364
00:19:01,503 --> 00:19:03,295
How we actually touch
365
00:19:03,551 --> 00:19:04,575
Collectible
366
00:19:05,087 --> 00:19:08,927
Are we detected two players even near the collectible in touching it
367
00:19:09,951 --> 00:19:12,511
When we gonna do there's use a simple box Collider
368
00:19:13,023 --> 00:19:14,815
Peter you sorted your coin
369
00:19:15,583 --> 00:19:17,119
A quick add component
370
00:19:17,375 --> 00:19:20,447
Can adults get a sprite renderer
371
00:19:20,959 --> 00:19:22,751
We have a collectible script on top of it
372
00:19:23,263 --> 00:19:24,799
Banana box Collider
373
00:19:25,311 --> 00:19:28,127
Be sure you select box Collider 2D
374
00:19:28,383 --> 00:19:30,175
And not the regular box Collider
375
00:19:30,943 --> 00:19:35,807
Regular box Collider is for 3D games and it's going to have a collision in the z-axis as well
376
00:19:36,319 --> 00:19:38,111
City of box Collider 2D
377
00:19:39,135 --> 00:19:41,695
Square head in zoom in here
378
00:19:42,207 --> 00:19:43,487
Take a look at what's going on
379
00:19:44,255 --> 00:19:46,559
No it's now we have a green box around
380
00:19:48,095 --> 00:19:49,887
It's actually a box Collider
381
00:19:50,399 --> 00:19:51,679
We can scale it up
382
00:19:52,191 --> 00:19:55,263
The extraction scale in the Y Direction
383
00:19:56,287 --> 00:19:58,847
Actually make it a little bit bigger than the coin
384
00:19:59,103 --> 00:20:01,151
Play match on 61
385
00:20:01,919 --> 00:20:02,687
Alex Grey
386
00:20:03,711 --> 00:20:04,735
Play
387
00:20:09,343 --> 00:20:10,111
Swan
388
00:20:11,135 --> 00:20:14,207
Should be able to actually stop when you touch
389
00:20:15,999 --> 00:20:17,535
Well what's happening is
390
00:20:19,327 --> 00:20:20,351
Is a Collider
391
00:20:20,607 --> 00:20:22,911
Colliding with the coin
392
00:20:23,423 --> 00:20:27,263
The way that you avoid this is actually just said it is Trigger
393
00:20:27,775 --> 00:20:31,615
Now we can walk through the coin but still detect
394
00:20:31,871 --> 00:20:34,175
If the player is touching the coin
395
00:20:34,687 --> 00:20:36,223
Play mode here
396
00:20:36,735 --> 00:20:39,039
Anfisa is Trigger is that a true
397
00:20:39,807 --> 00:20:44,415
We definitely want this to be true across the board for all coins
398
00:20:44,927 --> 00:20:47,487
Just go ahead and say is Trigger too true
399
00:20:47,743 --> 00:20:48,767
Are coin here
400
00:20:49,791 --> 00:20:50,303
And
401
00:20:50,815 --> 00:20:53,631
Then we're going to need to actually create a script
402
00:20:53,887 --> 00:20:56,447
Check to see if we actually touched
403
00:20:56,703 --> 00:20:57,215
Coin
404
00:20:57,727 --> 00:21:03,871
Are we definitely don't need to create a new script because we have a collectible script here we just need to create some more funk
405
00:21:04,127 --> 00:21:06,943
That's a text whether we touched that coin
406
00:21:07,455 --> 00:21:11,295
Double click on collectible here or just go back into Visual Studio
407
00:21:11,807 --> 00:21:13,599
Create a new function
408
00:21:13,855 --> 00:21:17,696
Actually a function that we can just go ahead and use right out of the box with unity
409
00:21:18,720 --> 00:21:19,232
So
410
00:21:19,744 --> 00:21:22,304
Is called ontriggerenter2d
411
00:21:22,816 --> 00:21:28,960
Never forget what is this guy's just Google trigger 2D unity and it'll probably show up
412
00:21:29,216 --> 00:21:29,984
The top of Google
413
00:21:30,240 --> 00:21:31,520
It's void
414
00:21:32,032 --> 00:21:38,176
On trigger enter or there is ontriggerenter2d not on trigger enter that's for
415
00:21:38,432 --> 00:21:42,784
Really just ontriggerenter2d and that's going to ignore the z-axis
416
00:21:45,600 --> 00:21:49,440
When heading created on trigger 2D function for us
417
00:21:49,696 --> 00:21:50,720
What is this mean
418
00:21:51,232 --> 00:21:57,376
What's 9 Saudi update so you know he's not gonna be running what's inside of this function
419
00:21:57,632 --> 00:21:58,144
All the time
420
00:21:58,656 --> 00:22:03,264
Is actually going to only run this when something triggers with this
421
00:22:03,520 --> 00:22:07,616
Specifically when something with a Collider and rigidbody
422
00:22:07,872 --> 00:22:08,896
And that's our player
423
00:22:09,408 --> 00:22:11,712
Collide with this project
424
00:22:12,480 --> 00:22:14,528
Telescope debug.log
425
00:22:16,064 --> 00:22:18,368
I'm touching something
426
00:22:20,416 --> 00:22:21,184
Save it out
427
00:22:21,696 --> 00:22:25,280
Let's go back in the unity and looks like there's no airs that's good
428
00:22:26,048 --> 00:22:29,376
We don't need a drag collectible anywhere because it's already attached
429
00:22:29,888 --> 00:22:30,912
Drag queen
430
00:22:31,168 --> 00:22:32,704
The code we just made
431
00:22:32,960 --> 00:22:34,496
Is actually ready to go
432
00:22:35,008 --> 00:22:36,032
Does it play
433
00:22:39,360 --> 00:22:42,432
Ok I'm Emma appeared in the console that's good
434
00:22:43,456 --> 00:22:44,736
Still there now script
435
00:22:45,248 --> 00:22:47,040
Touch the coin
436
00:22:47,552 --> 00:22:48,320
Right
437
00:22:49,088 --> 00:22:54,464
Awesome it is I'm touching something that is how it doesn't consistently print something into the console
438
00:22:54,720 --> 00:22:56,768
Why happens when I enter
439
00:22:57,280 --> 00:22:58,304
Collision area
440
00:22:59,072 --> 00:23:03,936
Take a look at the collision area there is a US small green box in the same window here
441
00:23:04,960 --> 00:23:06,496
The moment we touch that
442
00:23:10,848 --> 00:23:11,616
Perfect
443
00:23:12,128 --> 00:23:14,432
There's a little problem actually here
444
00:23:14,944 --> 00:23:19,552
What if I had a box so let's take this just for example
445
00:23:19,808 --> 00:23:22,112
What's pasty in make it look like a box
446
00:23:23,136 --> 00:23:24,416
I had a box
447
00:23:25,184 --> 00:23:31,328
Also had a rigidbody2d and again original body is what makes the object actual used
448
00:23:32,864 --> 00:23:34,144
If I had this box
449
00:23:34,400 --> 00:23:35,168
Right here
450
00:23:35,680 --> 00:23:36,960
Play
451
00:23:40,288 --> 00:23:43,104
And I moved is coming over
452
00:23:43,616 --> 00:23:46,176
You see that also interacting with the box
453
00:23:47,200 --> 00:23:48,992
We really don't want that because
454
00:23:49,248 --> 00:23:51,808
Checking if it's touching something
455
00:23:52,320 --> 00:23:55,648
It's going to be collected we are not boxes collecting things
456
00:23:56,160 --> 00:23:59,232
How do we actually check to see if only the player
457
00:23:59,488 --> 00:24:00,512
Is touching the Queen
458
00:24:01,024 --> 00:24:02,560
Taxi really simple
459
00:24:02,816 --> 00:24:04,352
Which is going to put a condition
460
00:24:04,608 --> 00:24:05,632
Inside of a function
461
00:24:06,144 --> 00:24:08,448
Was John back in the Visual Studio here
462
00:24:09,216 --> 00:24:11,520
Open up a script collectible that CS
463
00:24:11,776 --> 00:24:13,312
You must create a condition
464
00:24:13,824 --> 00:24:16,896
Inside of her on trigger enter 2D function
465
00:24:18,432 --> 00:24:19,712
Just gonna go something like this
466
00:24:20,224 --> 00:24:21,760
If the player
467
00:24:22,272 --> 00:24:23,552
Is touching
468
00:24:23,808 --> 00:24:24,576
Me
469
00:24:26,368 --> 00:24:27,136
Print
470
00:24:27,648 --> 00:24:28,672
Collect
471
00:24:31,232 --> 00:24:32,256
In the console
472
00:24:33,792 --> 00:24:35,328
What's this device year
473
00:24:37,120 --> 00:24:38,912
Write this condition out
474
00:24:39,680 --> 00:24:44,288
The way we write this is actually we would use the variable that's included
475
00:24:44,800 --> 00:24:50,944
In the parameters this parentheses is the parameters section of the function that doesn't
476
00:24:51,200 --> 00:24:53,504
Make sense soon we're gonna use this a lot
477
00:24:54,784 --> 00:25:00,928
What are the parameters included in the ontriggerenter2d is the collision or the collider2d
478
00:25:01,184 --> 00:25:07,328
Basically this allows us to know certain information about the collider that's touching the Collector
479
00:25:08,096 --> 00:25:10,144
So what we would write is if
480
00:25:10,400 --> 00:25:11,424
Collision
481
00:25:11,936 --> 00:25:17,568
That's the variable name here lies a very curious of something a variable just look for the lowercase letter
482
00:25:18,080 --> 00:25:19,872
If collision dot
483
00:25:20,128 --> 00:25:22,944
Game object name
484
00:25:23,456 --> 00:25:24,736
Equals equals
485
00:25:25,248 --> 00:25:26,016
Player
486
00:25:26,784 --> 00:25:28,576
Then we're going to do something right
487
00:25:28,832 --> 00:25:31,648
Debug.log collect
488
00:25:37,280 --> 00:25:39,072
Looks like we forgot her
489
00:25:39,840 --> 00:25:41,120
Close princess is here
490
00:25:41,888 --> 00:25:42,656
Erika
491
00:25:42,912 --> 00:25:44,448
Analitik play
492
00:25:44,960 --> 00:25:45,984
And see what happens
493
00:25:50,336 --> 00:25:56,224
Looks like if I jump up on the platform here and when the right like collect is being fired
494
00:25:56,992 --> 00:25:57,504
Perfect
495
00:25:58,528 --> 00:26:01,600
Alright let's check and see if this box
496
00:26:01,856 --> 00:26:02,624
Dear
497
00:26:03,392 --> 00:26:06,464
Will do the same thing we definitely got one at 2 but that's check
498
00:26:07,744 --> 00:26:11,584
Good looks like nothing's happening even if I clear the console window
499
00:26:13,120 --> 00:26:16,192
Not interacting with the coin that's perfect
500
00:26:16,448 --> 00:26:17,216
Alright
501
00:26:19,008 --> 00:26:20,032
Really quick
502
00:26:20,544 --> 00:26:21,568
What is the white the
503
00:26:22,080 --> 00:26:23,616
Coin to disappear
504
00:26:24,128 --> 00:26:25,152
Emily white
505
00:26:25,408 --> 00:26:28,992
A new player script to actually add a coin to its inventory
506
00:26:29,248 --> 00:26:30,784
It's actually really simple
507
00:26:31,296 --> 00:26:37,440
Are we going to do with type game object in lowercase game object is actually just a reference that
508
00:26:37,696 --> 00:26:41,280
The news for the actual game object that contains the Script
509
00:26:41,536 --> 00:26:42,304
Turn this case
510
00:26:42,560 --> 00:26:43,584
A coin
511
00:26:43,840 --> 00:26:45,632
That said active
512
00:26:46,400 --> 00:26:47,168
To force
513
00:26:47,424 --> 00:26:53,568
Set the parent object so that's the coin in any children inside of the Queen Sofia
514
00:26:53,824 --> 00:26:59,968
What goes inside a bitcoin or maybe some players are some gloves disabled as well or dry
515
00:27:00,224 --> 00:27:03,808
What is a better word meaning of the word deactivated
516
00:27:04,064 --> 00:27:06,112
Not disabled or enabled
517
00:27:06,624 --> 00:27:09,184
Because enabled in disabled or referencing
518
00:27:09,440 --> 00:27:14,048
Enabling in disabling scripts this is enabling and disabling
519
00:27:14,304 --> 00:27:15,584
The polygon Collider
520
00:27:15,840 --> 00:27:18,912
Is disabling and enabling the sprite renderer
521
00:27:19,168 --> 00:27:23,520
This is deactivating the game object the other gameobject is now
522
00:27:24,032 --> 00:27:24,800
Dawn
523
00:27:25,824 --> 00:27:27,104
Open the actual scene
524
00:27:27,616 --> 00:27:33,504
And it's also faded out your dad's deactivating so you can have to memorise activating
525
00:27:33,760 --> 00:27:38,880
Is related to this toggle here which deactivates a gameobject entirely
526
00:27:39,392 --> 00:27:43,488
Includes stopping all of the scripts associated with it
527
00:27:43,744 --> 00:27:46,560
So think about this is pulling the power plug
528
00:27:46,816 --> 00:27:50,912
For your actual game objects I want to deactivate this coin
529
00:27:51,168 --> 00:27:55,520
I'm pulling the power plug to the entire thing I must destroy it entirely
530
00:27:55,776 --> 00:28:00,384
All of the scripts the spray render at the box Collider at the collectible clothes off stop
531
00:28:00,640 --> 00:28:03,456
Disabling the collectible script
532
00:28:04,480 --> 00:28:10,624
Just stop the Script by the renderer for the Sprite will still be there the game object is still running
533
00:28:10,880 --> 00:28:14,208
Ask later is still there we just disabling The Script
534
00:28:14,976 --> 00:28:16,512
So when I deactivate
535
00:28:16,768 --> 00:28:18,816
The entire game object
536
00:28:19,072 --> 00:28:23,168
The way you do that is gameobject set active
537
00:28:23,680 --> 00:28:26,496
Go ahead and hit play
538
00:28:27,008 --> 00:28:29,312
See if that actually does what we need it to
539
00:28:29,568 --> 00:28:32,128
The moment we touched the coin it should just disappear
540
00:28:34,944 --> 00:28:35,712
Jump
541
00:28:38,784 --> 00:28:39,808
Regardless of the Queen
542
00:28:40,576 --> 00:28:41,344
Awesome
543
00:28:42,368 --> 00:28:46,720
Another way of achieving a similar effect is actually just destroying the object
544
00:28:46,976 --> 00:28:53,120
So we can pull the power plug or deactivate the object or we can just destroy it entirely
545
00:28:53,376 --> 00:28:55,424
Does comment out this line
546
00:28:55,936 --> 00:28:59,008
Actually just destroyed the game and you can see what happens
547
00:28:59,264 --> 00:29:00,288
Destroy
548
00:29:01,056 --> 00:29:02,848
What game effect
549
00:29:03,872 --> 00:29:10,016
Really quick guys any time you see something inside of a printer sees when were calling or doing a function like
550
00:29:10,272 --> 00:29:10,784
Destroy
551
00:29:11,296 --> 00:29:13,088
That's called the parameters
552
00:29:13,600 --> 00:29:17,440
Cell parameters are passed through functions so in this case
553
00:29:17,952 --> 00:29:22,816
Inside of the Destroy function which is a function we can use inside of any game object
554
00:29:23,840 --> 00:29:27,424
There are actually two parameters inside of the Destroy function
555
00:29:27,680 --> 00:29:33,056
What do you want to destroy that's the game object but if you press the comma key
556
00:29:33,568 --> 00:29:36,128
You can actually see right here can you give us a hint
557
00:29:36,384 --> 00:29:37,152
Float
558
00:29:37,408 --> 00:29:37,920
T
559
00:29:38,176 --> 00:29:41,504
Does that mean that means well how many seconds do we want to wait
560
00:29:41,760 --> 00:29:42,784
To destroy
561
00:29:43,296 --> 00:29:46,624
We can do 0 f or just remove it entirely
562
00:29:47,136 --> 00:29:49,696
Is going to destroy the gameobject immediately
563
00:29:50,208 --> 00:29:51,488
To see how this looks
564
00:29:52,000 --> 00:29:53,024
Go ahead Nick play
565
00:29:56,864 --> 00:29:58,912
Well unsurprisingly
566
00:29:59,936 --> 00:30:00,960
Identical
567
00:30:01,216 --> 00:30:03,776
But you can see it's been removed entirely
568
00:30:04,032 --> 00:30:05,568
Hierarchy here
569
00:30:07,872 --> 00:30:10,944
Was coins like that actually I'm ok with destroying the coin
570
00:30:11,456 --> 00:30:17,600
Everything is once we exit play mode it's not actually destroying it permanently it's just destroying it in play mode
571
00:30:18,368 --> 00:30:24,000
Can I see ok with that I'm fine destroying the coin because I know we never going to be able to collect a coin again
572
00:30:24,256 --> 00:30:25,536
When were playing this game
573
00:30:25,792 --> 00:30:31,168
That's fine we can keep destroy that came object remove this comment here
574
00:30:32,704 --> 00:30:38,848
There we go save it out just know you disable components and scripts you can deactivate
575
00:30:39,104 --> 00:30:40,896
Object that is pulling the power plug
576
00:30:41,152 --> 00:30:46,016
Or we can destroy gameobject entirely and destroys everything associated with them
577
00:30:46,272 --> 00:30:50,880
Game object to transform the components the scripts running on it
578
00:30:51,136 --> 00:30:57,024
Everything we talking about parameters during this course so don't worry too much if it doesn't make sense
579
00:30:57,792 --> 00:31:02,656
Ok so what if we wanted the player to actually collect this coin
580
00:31:03,424 --> 00:31:06,496
Where would a coin go if we just destroy the coin
581
00:31:06,752 --> 00:31:07,776
Where is a girl
582
00:31:08,288 --> 00:31:13,408
What everything in video games guys it's stored in simple variables
583
00:31:13,664 --> 00:31:19,808
Directly going anywhere it's like the Queen is going into this game objects pocket as I was going
584
00:31:20,064 --> 00:31:24,672
Not even going to a UI element inside a move to a UI element
585
00:31:24,928 --> 00:31:28,000
All we want to do is tell the player
586
00:31:28,512 --> 00:31:33,376
That we have a coin that's all we need to know we need to know how many coins is a player have
587
00:31:33,632 --> 00:31:35,168
That's the most important thing
588
00:31:35,424 --> 00:31:40,288
Then we can make graphics for the screen lighter that reflect how many coins we have
589
00:31:41,056 --> 00:31:45,920
So all we need to do is increase the coin amount the player has
590
00:31:46,432 --> 00:31:47,200
I want
591
00:31:47,968 --> 00:31:51,296
The way we do that is not inside of a collectible script just yet
592
00:31:51,552 --> 00:31:54,624
Yes you need to create a new variable inside of new player
593
00:31:54,880 --> 00:31:56,672
What's double click new player here
594
00:31:57,440 --> 00:32:03,584
Create a new variable called private integer because you can only get pieces of coins
595
00:32:03,840 --> 00:32:08,192
Play this is going to be the one going to coins a million coins etc
596
00:32:08,704 --> 00:32:11,008
Private ENT coins
597
00:32:13,568 --> 00:32:15,360
Coins collected
598
00:32:16,896 --> 00:32:20,736
And by default it's going to be 0 so we don't need to actually write that out
599
00:32:21,248 --> 00:32:22,016
Semicolon
600
00:32:22,528 --> 00:32:25,856
Now we have a new variable called coins collected
601
00:32:26,880 --> 00:32:27,392
Great
602
00:32:27,648 --> 00:32:30,208
Now if we're going to a collectible script here
603
00:32:31,488 --> 00:32:37,632
Before we destroy the coin when we collect it we need to make sure we increase the players coin and
604
00:32:38,400 --> 00:32:43,008
The way we do there is through the game object that find command
605
00:32:43,520 --> 00:32:46,848
And then also gameobject at getcomponent command
606
00:32:47,360 --> 00:32:51,968
This is probably some of the weirdest syntax you can be using
607
00:32:52,224 --> 00:32:54,016
When you're writing c-sharp scripts
608
00:32:54,528 --> 00:32:57,600
And this was one that I certainly had memorise
609
00:32:57,856 --> 00:33:02,464
So don't get overwhelmed we going to do this a lot when we're creating a game
610
00:33:02,720 --> 00:33:07,584
So just practise riding with script because you're going to be using this a lot inside of Unity
611
00:33:08,352 --> 00:33:12,704
So to find the player we go game object that find
612
00:33:14,240 --> 00:33:18,080
Player so it's going to look for a game object called player
613
00:33:18,592 --> 00:33:24,736
Do you know if he's going to look around going to get a magnifying glass is that looking around in the scene really quickly
614
00:33:25,248 --> 00:33:27,808
Or a game object card player
615
00:33:28,064 --> 00:33:29,344
If I find one
616
00:33:30,112 --> 00:33:32,160
Is going to look for a component
617
00:33:32,416 --> 00:33:34,976
Gameobject get component
618
00:33:35,232 --> 00:33:39,072
And another way of putting this is going to look for a script that's currently running
619
00:33:39,328 --> 00:33:41,632
Look for the new player script
620
00:33:41,888 --> 00:33:42,912
Sky News
621
00:33:43,936 --> 00:33:48,288
Less than and greater than sign here and we're going to do new player
622
00:33:48,800 --> 00:33:52,640
And then to parentheses I know it's weird but that's just the same tax
623
00:33:53,152 --> 00:33:53,664
Diet
624
00:33:54,944 --> 00:33:55,712
Was it called
625
00:33:56,224 --> 00:33:56,992
Coins
626
00:33:57,248 --> 00:33:58,016
Elected
627
00:33:59,296 --> 00:34:00,832
Equals 1
628
00:34:03,392 --> 00:34:09,536
So that's how we actually look for a game object and then we look for the component associated with it
629
00:34:09,792 --> 00:34:10,816
Which is new player
630
00:34:11,072 --> 00:34:13,888
Which again that's where are coins collected very Berlin
631
00:34:14,144 --> 00:34:17,216
Variable is not inside of the game object
632
00:34:17,472 --> 00:34:19,264
Is the side of the component
633
00:34:19,520 --> 00:34:25,152
On the game object take a look at unity here we'll get an error thrown don't worry about it
634
00:34:25,664 --> 00:34:27,200
What's like a player here
635
00:34:29,760 --> 00:34:30,528
Serious
636
00:34:31,808 --> 00:34:33,856
There's a new player script
637
00:34:34,368 --> 00:34:40,512
On the player game object this is the game object the name player
638
00:34:40,768 --> 00:34:41,280
Air player
639
00:34:41,792 --> 00:34:47,168
There's a component or a script again component in script are pretty much synonymous
640
00:34:47,936 --> 00:34:49,984
Is a new player script on here
641
00:34:50,240 --> 00:34:56,128
Inside of the new player script there is a variable called coins collected
642
00:34:56,640 --> 00:35:00,992
So this gameobject define player.get component
643
00:35:02,016 --> 00:35:06,624
That coins collected is just a way for us to slowly trail into
644
00:35:06,880 --> 00:35:07,648
The Script
645
00:35:08,416 --> 00:35:11,744
I'm looking see ok is there a coin collector variable
646
00:35:12,000 --> 00:35:14,304
If there is set it to 1
647
00:35:14,560 --> 00:35:15,072
Ok
648
00:35:16,352 --> 00:35:16,864
Now
649
00:35:17,376 --> 00:35:21,728
I know that there might be a little bit confusing to trust me we're going to be using this or what
650
00:35:21,984 --> 00:35:28,128
So if you feel overwhelmed right now just type this out in we're going to keep practising it's going to become s
651
00:35:28,384 --> 00:35:30,176
Promise don't get overwhelmed
652
00:35:30,432 --> 00:35:31,968
I'm looking for the player
653
00:35:32,224 --> 00:35:34,528
I'm looking for the component you player
654
00:35:35,040 --> 00:35:38,624
And then we're looking for a variable called coins collected
655
00:35:39,392 --> 00:35:40,672
What is a problem here
656
00:35:41,184 --> 00:35:44,512
When collected has a red zigzag and why is that
657
00:35:45,024 --> 00:35:48,608
Well it's actually inaccessible due to its protection level
658
00:35:49,120 --> 00:35:51,680
That means that it's private
659
00:35:52,192 --> 00:35:57,312
That's my private and public variable are that didn't make sense in the earlier sections of this course
660
00:35:57,824 --> 00:36:02,432
It's private meaning I can access it inside of new player so I could type
661
00:36:02,688 --> 00:36:03,712
Coins
662
00:36:03,968 --> 00:36:06,272
Collected = 200 rate
663
00:36:06,528 --> 00:36:08,320
I could do that all day long I wanted to
664
00:36:08,832 --> 00:36:12,416
Because I'm inside of a new player script in me
665
00:36:12,672 --> 00:36:14,208
And this script is
666
00:36:14,464 --> 00:36:19,584
Changing this variable that's because it's private means I can only do it instead of The Script
667
00:36:19,840 --> 00:36:24,192
So this is an instance where we go look we have to be public
668
00:36:24,448 --> 00:36:27,008
The coins collected is a public variable
669
00:36:27,520 --> 00:36:29,568
Meaning other scripts can access it
670
00:36:29,824 --> 00:36:30,592
Delete this
671
00:36:32,128 --> 00:36:32,896
Now
672
00:36:33,152 --> 00:36:34,688
Exec is gone
673
00:36:35,200 --> 00:36:40,064
That means we can set coins collected one the moment we collect this coin
674
00:36:40,832 --> 00:36:42,624
The lift test for sale
675
00:36:42,880 --> 00:36:44,160
Play here
676
00:36:47,744 --> 00:36:48,768
And run
677
00:36:49,536 --> 00:36:50,560
And then jump
678
00:36:51,840 --> 00:36:53,120
First off
679
00:36:53,632 --> 00:36:54,656
Where we collect a coin
680
00:36:54,912 --> 00:36:56,448
Let's see how many coins we have
681
00:36:56,704 --> 00:36:58,496
We have 0 over here
682
00:36:58,752 --> 00:36:59,776
In the new player
683
00:37:00,032 --> 00:37:00,544
Campania
684
00:37:02,336 --> 00:37:03,104
I ran over
685
00:37:04,384 --> 00:37:06,432
Looks like coin collecting is one
686
00:37:06,944 --> 00:37:09,248
Awesome that's great so now we have
687
00:37:10,016 --> 00:37:11,040
A coin
688
00:37:11,808 --> 00:37:15,904
Don't go heading copy and paste this coin all over the place in start collecting coins
689
00:37:16,416 --> 00:37:17,952
Let's be careful though
690
00:37:18,208 --> 00:37:21,536
We actually go inside of this prefab and take a look at it
691
00:37:22,048 --> 00:37:25,632
What is the prefab only has a Sprite renderer attached to it
692
00:37:26,144 --> 00:37:27,424
Where did everything go
693
00:37:27,680 --> 00:37:28,192
Well
694
00:37:28,448 --> 00:37:30,496
What we've added to this coin
695
00:37:30,752 --> 00:37:35,872
Are additional features that are necessarily at the root level of the prefab
696
00:37:36,128 --> 00:37:37,920
Is there a digital features
697
00:37:38,176 --> 00:37:38,944
With added
698
00:37:39,456 --> 00:37:45,600
How do we apply them to the prefab so that this prefab is identical across the game
699
00:37:45,856 --> 00:37:46,624
When we duplicate
700
00:37:47,648 --> 00:37:49,440
The way we do that is we can either
701
00:37:49,696 --> 00:37:55,840
Add each one individually inside of the prefab here and edit the route prefab so we could add a 4
702
00:37:56,096 --> 00:37:58,656
Collider we could add the collectible script
703
00:37:59,936 --> 00:38:01,216
Is a better way to do that
704
00:38:01,728 --> 00:38:03,776
Go back into a scene here
705
00:38:04,288 --> 00:38:05,824
I'm here
706
00:38:06,592 --> 00:38:10,688
Allow us to apply all of the changes to this prefab
707
00:38:11,456 --> 00:38:14,528
To the original route prefab coin
708
00:38:15,296 --> 00:38:19,904
Anyway be careful doing this is a basically like saving over a document
709
00:38:20,160 --> 00:38:26,304
When you're actually working in Microsoft Word or Photoshop or something this is basically saving over a prefab
710
00:38:26,560 --> 00:38:30,400
Well we don't have any other coins in a game without been using anywhere else
711
00:38:30,656 --> 00:38:32,704
Go ahead and hit apply
712
00:38:34,240 --> 00:38:37,312
Now when we drag the coin prefab into the game
713
00:38:39,104 --> 00:38:41,664
Has all of the same properties
714
00:38:42,432 --> 00:38:45,248
Including the box Collider in The Script on it
715
00:38:45,760 --> 00:38:47,296
The other coin has
716
00:38:50,368 --> 00:38:51,392
That looks great
717
00:38:51,904 --> 00:38:57,792
Let's be sure we keep things clean and going to be tempted to just create a game guys and that actually clean up
718
00:38:58,048 --> 00:39:02,144
So what you want to do is actually drag this down but put it next to the other coin
719
00:39:02,400 --> 00:39:03,424
In hierarchy
720
00:39:03,936 --> 00:39:05,728
Just so everything is nice and organised
721
00:39:06,752 --> 00:39:10,336
Sweet so now we have all these coins so I had hit play here
722
00:39:12,640 --> 00:39:14,176
Insert collecting coins
723
00:39:14,944 --> 00:39:18,528
That's great so we've collected 12
724
00:39:19,296 --> 00:39:20,064
Masham
725
00:39:21,344 --> 00:39:23,392
345
726
00:39:24,160 --> 00:39:27,488
Let's take a look at our player here and make sure he's collected 5 coins
727
00:39:28,000 --> 00:39:30,816
Does collapse all the players here just click on player here
728
00:39:32,608 --> 00:39:34,656
Looks like we still only have one coin
729
00:39:35,168 --> 00:39:35,936
What's going on
730
00:39:36,448 --> 00:39:40,032
What the reason that is is because we just set the variable
731
00:39:41,056 --> 00:39:41,824
1
732
00:39:42,336 --> 00:39:43,616
We need iterator
733
00:39:43,872 --> 00:39:45,408
30 plus equals
734
00:39:45,664 --> 00:39:46,176
1
735
00:39:46,944 --> 00:39:53,088
Anything goes when I go to use time that deltatime remember that for like counters and moving
736
00:39:53,344 --> 00:39:54,112
Update
737
00:39:54,624 --> 00:39:56,928
Just collecting integer
738
00:39:57,184 --> 00:39:58,976
Plus equals one is fine
739
00:39:59,232 --> 00:40:05,376
Because it's ontriggerenter meaning with touched it once with entered into the box Collider
740
00:40:05,632 --> 00:40:08,704
It's only going to do it once that's fine
741
00:40:08,960 --> 00:40:10,752
We don't need time to time here
742
00:40:11,008 --> 00:40:15,104
Not again guys + = 1 is the same as riding this
743
00:40:15,360 --> 00:40:21,504
Find player that get component new player that coins collected equals gameobject that's fine
744
00:40:21,760 --> 00:40:23,296
Ms carpets
745
00:40:23,552 --> 00:40:27,392
Is the same thing is equal in itself plus 1
746
00:40:27,648 --> 00:40:30,464
So if itself equals 2 is going to add
747
00:40:32,256 --> 00:40:33,280
Plus 1
748
00:40:33,536 --> 00:40:35,840
So if coin collected equals to
749
00:40:36,096 --> 00:40:40,192
What is going to say collected = coins collected + 1
750
00:40:40,704 --> 00:40:41,984
Then it turns 23
751
00:40:42,496 --> 00:40:48,384
Then the next time you got to go in it will take me 3 so it's going to equal 3 + 1 which is or
752
00:40:48,896 --> 00:40:51,712
A quicker way to write this is just plus equals
753
00:40:52,224 --> 00:40:53,248
That's all that is
754
00:40:53,504 --> 00:40:57,856
And now we're going to either way up one when we actually collect the collectible
755
00:40:59,392 --> 00:40:59,904
Ok
756
00:41:00,160 --> 00:41:00,928
Set alarm
757
00:41:05,792 --> 00:41:08,096
Soccer player so we can watch it
758
00:41:09,376 --> 00:41:15,520
Ways to test guys you can have either your coins getting printed to the console or you can just look at
759
00:41:15,776 --> 00:41:17,824
You see realised or public variables
760
00:41:18,080 --> 00:41:19,616
In the inspector over here
761
00:41:20,128 --> 00:41:21,664
We have one coin
762
00:41:23,456 --> 00:41:25,248
No I had to Great
763
00:41:28,320 --> 00:41:33,184
Now we have three looks like it's working awesome so now we can collect coins in a game
56886
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.