1
00:00:00,000 --> 00:00:03,690
Welcome back, My favorite game developers.

2
00:00:03,690 --> 00:00:06,540
In this video, we are going to be creating

3
00:00:06,540 --> 00:00:11,180
our first script and adding it to our doom player.

4
00:00:11,175 --> 00:00:14,675
Not only that, we are going to be learning a lot of things,

5
00:00:14,670 --> 00:00:17,970
we are going to be learning what this scary word means.

6
00:00:17,970 --> 00:00:19,710
We're going to learn about variables.

7
00:00:19,710 --> 00:00:21,210
We're going to learn about inputs.

8
00:00:21,210 --> 00:00:23,070
We're going to learn about vector 2.

9
00:00:23,070 --> 00:00:26,910
We are going to be learning how start and update work separately.

10
00:00:26,910 --> 00:00:28,760
So with that said,

11
00:00:28,755 --> 00:00:31,265
this is a bit of a longer video if you want,

12
00:00:31,260 --> 00:00:33,510
but if you're a beginner, it's very important,

13
00:00:33,510 --> 00:00:36,350
very crucial to understand everything.

14
00:00:36,345 --> 00:00:41,245
So let's not waste any more time and let's get started.

15
00:00:41,245 --> 00:00:45,785
Oh, okay, so time for some scripting.

16
00:00:45,785 --> 00:00:49,075
The first thing we're going to do is we're going to create

17
00:00:49,070 --> 00:00:53,120
a script and assign it to the doom player.

18
00:00:53,120 --> 00:00:56,570
Now, there are many ways of creating scripts and there

19
00:00:56,570 --> 00:01:00,010
are many ways of assigning scripts to certain objects.

20
00:01:00,005 --> 00:01:01,405
They are all the same.

21
00:01:01,400 --> 00:01:04,040
Let's start off with the most basic one,

22
00:01:04,040 --> 00:01:07,550
and that is simply clicking on the game object.

23
00:01:07,550 --> 00:01:10,280
You can see right here that we have the transform.

24
00:01:10,280 --> 00:01:12,950
It is one of the components that we have.

25
00:01:12,950 --> 00:01:17,450
We can add another component right here by clicking on it.

26
00:01:17,450 --> 00:01:21,740
Now, you can see that we have many components that we can add,

27
00:01:21,740 --> 00:01:24,040
ranging from audio to affect,

28
00:01:24,035 --> 00:01:25,775
to physics and so on.

29
00:01:25,775 --> 00:01:30,755
But we also have this option right here of adding scripts.

30
00:01:30,755 --> 00:01:35,455
We can click on it. We can see through it and add whichever script that we want.

31
00:01:35,450 --> 00:01:37,250
Or even easier than that,

32
00:01:37,250 --> 00:01:41,980
we can simply start typing in the name of the script that we want to add.

33
00:01:41,975 --> 00:01:47,095
And the script that we want to call or create will be the player controller.

34
00:01:47,090 --> 00:01:52,210
So we're going to create layer controller right here and make

35
00:01:52,210 --> 00:01:58,060
sure that you create the name to be a single sentence without any spaces.

36
00:01:58,060 --> 00:02:01,420
You can see right here we have the option for a new script.

37
00:02:01,420 --> 00:02:02,470
Let's click on it.

38
00:02:02,470 --> 00:02:05,880
You can see the name as player controller.

39
00:02:05,875 --> 00:02:08,175
And now we can create the script,

40
00:02:08,170 --> 00:02:13,060
but make sure that shoe figure out correct word or the correct

41
00:02:13,060 --> 00:02:18,220
name for the script because it will be the name of the class inside of this script.

42
00:02:18,220 --> 00:02:22,110
This will be very crucial as you create scripts later on.

43
00:02:22,105 --> 00:02:24,675
So we're going to create an ad.

44
00:02:24,670 --> 00:02:27,970
Wait for just a little bit.

45
00:02:27,970 --> 00:02:32,810
And now we should see that we have the script ready.

46
00:02:32,810 --> 00:02:34,250
If we click on it right here,

47
00:02:34,250 --> 00:02:38,330
we can see in the Inspector what this script will look like.

48
00:02:38,330 --> 00:02:41,180
And now we are going to double-click.

49
00:02:41,180 --> 00:02:44,770
And you can see that Visual Studio is opening up.

50
00:02:44,765 --> 00:02:45,185
Now.

51
00:02:45,185 --> 00:02:51,025
One of the things many people or many students of mine keep asking me over and over.

52
00:02:51,020 --> 00:02:55,850
If your script doesn't open up using Visual Studio, or for example,

53
00:02:55,850 --> 00:03:01,420
when you type something in here and you don't get the recommendations by Visual Studio,

54
00:03:01,415 --> 00:03:07,355
you can go into the that, go to Preferences,

55
00:03:07,355 --> 00:03:10,025
go to the External Tools,

56
00:03:10,025 --> 00:03:12,355
and in the external script editor,

57
00:03:12,350 --> 00:03:15,640
make sure that you have Visual Studio Community.

58
00:03:15,635 --> 00:03:19,385
You can choose our IDEs like Visual Studio Code.

59
00:03:19,385 --> 00:03:26,105
But me personally, I like or prefer to use the Visual Studio Community 2019.

60
00:03:26,105 --> 00:03:28,765
It's much better and smoother than the studio.

61
00:03:28,760 --> 00:03:32,620
Sometimes studio just has its quirks where it doesn't show up,

62
00:03:32,615 --> 00:03:33,985
doesn't open up correctly.

63
00:03:33,980 --> 00:03:37,540
So I prefer using Visual Studio Community.

64
00:03:37,535 --> 00:03:38,305
That's free.

65
00:03:38,300 --> 00:03:39,040
It works.

66
00:03:39,035 --> 00:03:40,225
Let's continue on.

67
00:03:40,220 --> 00:03:40,850
Now.

68
00:03:40,850 --> 00:03:43,930
We have our script opened up right here.

69
00:03:43,925 --> 00:03:47,845
We have the libraries that we can use.

70
00:03:47,840 --> 00:03:51,100
We have the class name, the player controller.

71
00:03:51,095 --> 00:03:56,435
It should always have the same name as the script that we've created right here.

72
00:03:56,435 --> 00:04:00,985
So you can see player controller under no circumstances do you

73
00:04:00,980 --> 00:04:06,400
change the name of the script in here without changing the class name?

74
00:04:06,395 --> 00:04:08,155
Don't even try to do that.

75
00:04:08,150 --> 00:04:10,850
It will create a lot of problems.

76
00:04:10,849 --> 00:04:12,969
What do we have here? It's a public,

77
00:04:12,965 --> 00:04:14,305
we'll see what that means.

78
00:04:14,300 --> 00:04:17,320
It's a class, it's mono behavior.

79
00:04:17,315 --> 00:04:23,555
Monte behavior gives us the ability to use things such as start and update.

80
00:04:23,555 --> 00:04:26,765
What is start? Start is a method.

81
00:04:26,765 --> 00:04:28,885
We'll see later on what methods are.

82
00:04:28,880 --> 00:04:32,780
But for now all you need to know any code that we write inside of

83
00:04:32,780 --> 00:04:38,600
the star gets executed as soon as we start our game,

84
00:04:38,600 --> 00:04:40,640
if that object is turned on,

85
00:04:40,640 --> 00:04:43,690
of course, we'll see what that also means later on.

86
00:04:43,685 --> 00:04:45,215
An update, as you can see,

87
00:04:45,215 --> 00:04:47,455
update is called once per frame.

88
00:04:47,450 --> 00:04:49,990
So if we have, for example,

89
00:04:49,985 --> 00:04:54,625
things that we want to call every single frame update is perfect

90
00:04:54,620 --> 00:04:58,940
for that and we will see all of this as we progress through this course.

91
00:04:58,940 --> 00:05:01,430
You'll understand everything, don't worry about it.

92
00:05:01,430 --> 00:05:07,700
Now, the first thing we need to do is we need a way to move our player.

93
00:05:07,700 --> 00:05:13,790
We will do that by taking inputs from the arrow keys or the WASD keys.

94
00:05:13,790 --> 00:05:15,430
But before we do that,

95
00:05:15,425 --> 00:05:18,815
there is something that we need to take into consideration and that

96
00:05:18,815 --> 00:05:22,405
is the movement speed of our player.

97
00:05:22,400 --> 00:05:26,120
And for that, we are going to need a variable.

98
00:05:26,120 --> 00:05:30,890
What is a variable when it comes to C-sharp? Let me explain.

99
00:05:30,890 --> 00:05:34,010
Variables are like boxes.

100
00:05:34,010 --> 00:05:36,070
So we have a box,

101
00:05:36,065 --> 00:05:38,665
we give it the name lives,

102
00:05:38,660 --> 00:05:42,650
and we put inside that box a number three.

103
00:05:42,650 --> 00:05:49,600
So now we have a variable obtain lives that has a three inside of it.

104
00:05:49,595 --> 00:05:55,535
So this is how we create the code for this box or valuable.

105
00:05:55,535 --> 00:05:58,675
We start off by giving the accessibility.

106
00:05:58,670 --> 00:06:01,580
So where can you access this variable?

107
00:06:01,580 --> 00:06:04,790
Can either be public or it can be private.

108
00:06:04,790 --> 00:06:08,060
If it's private, we can only access it inside

109
00:06:08,060 --> 00:06:11,470
of the class we've created, not from outside.

110
00:06:11,465 --> 00:06:16,165
If it's public, we can exit from any other script that we want.

111
00:06:16,160 --> 00:06:18,850
We need to assign the type of the variable.

112
00:06:18,845 --> 00:06:20,545
So we have multiple types,

113
00:06:20,540 --> 00:06:22,970
we have integers, strings and so on.

114
00:06:22,970 --> 00:06:26,420
We will see in just a bit what other types we have.

115
00:06:26,420 --> 00:06:28,390
We have the name of the variable.

116
00:06:28,385 --> 00:06:30,805
Obviously, every variable should have a name.

117
00:06:30,800 --> 00:06:32,240
How else do we call it?

118
00:06:32,240 --> 00:06:36,550
And we have the data that is inside of this variable.

119
00:06:36,545 --> 00:06:40,495
So this is how we create a variable in C Sharp.

120
00:06:40,490 --> 00:06:42,590
And this is the representation if you want,

121
00:06:42,590 --> 00:06:47,830
It's just like a box that we put things and then we move on.

122
00:06:47,825 --> 00:06:50,935
We have different types of variables.

123
00:06:50,930 --> 00:06:53,600
And the first type is a velocity.

124
00:06:53,600 --> 00:06:58,580
So an integer is a normal number, let's say 123456.

125
00:06:58,580 --> 00:07:02,450
A float is, let's say 4.8.

126
00:07:02,450 --> 00:07:03,880
Why do we have a float?

127
00:07:03,875 --> 00:07:10,655
Because sometimes the speed of something or the velocity of a car isn't just five or six.

128
00:07:10,655 --> 00:07:13,195
It can be 6.32,

129
00:07:13,190 --> 00:07:17,710
it can be 6.9, it can be 6.9456.

130
00:07:17,705 --> 00:07:19,685
So we need a float,

131
00:07:19,685 --> 00:07:21,625
and this is how we create a float.

132
00:07:21,620 --> 00:07:23,690
We always add the data.

133
00:07:23,690 --> 00:07:27,400
So the 4.8 with an F on the end.

134
00:07:27,395 --> 00:07:29,785
Then we have a Boolean.

135
00:07:29,780 --> 00:07:34,310
The Boolean is usually either true or it's false.

136
00:07:34,310 --> 00:07:39,710
So for example, let's say we want to determine whether a player is dead or not.

137
00:07:39,710 --> 00:07:42,130
So as he, that he is dead,

138
00:07:42,125 --> 00:07:44,015
then the variable is true.

139
00:07:44,015 --> 00:07:45,425
If he's not dead,

140
00:07:45,425 --> 00:07:48,335
then the variable is that S false.

141
00:07:48,335 --> 00:07:50,035
Finally, we have a string.

142
00:07:50,030 --> 00:07:54,500
So for example, what is a string of characters?

143
00:07:54,500 --> 00:07:56,120
We have multiple characters,

144
00:07:56,120 --> 00:07:57,410
one after the other.

145
00:07:57,410 --> 00:08:00,020
I see h, e, l.

146
00:08:00,020 --> 00:08:04,290
That string of characters is Michael.

147
00:08:04,294 --> 00:08:09,484
So we call a variable of type string with the name my name,

148
00:08:09,485 --> 00:08:11,365
and it represents michael.

149
00:08:11,360 --> 00:08:17,440
Make sure whenever you create a string variable that is between these two quotes.

150
00:08:17,435 --> 00:08:20,705
Okay, now, with all these variables done with,

151
00:08:20,705 --> 00:08:25,175
Let's go ahead and create our own variable in the scripts right here.

152
00:08:25,175 --> 00:08:27,635
So the first thing we're going to do,

153
00:08:27,635 --> 00:08:32,635
as we are going to create something called a serialized field.

154
00:08:32,630 --> 00:08:36,290
Now, don't be scared of this long name.

155
00:08:36,290 --> 00:08:38,200
It's going to be an integer,

156
00:08:38,195 --> 00:08:41,735
and it's going to be called the movement speed.

157
00:08:41,735 --> 00:08:46,615
Now this will determined how fast our player moves as we

158
00:08:46,610 --> 00:08:51,880
implemented your understand and why are we using something called the serialized field.

159
00:08:51,875 --> 00:08:53,425
You just told me, Michael,

160
00:08:53,420 --> 00:08:55,580
that it's either public or private.

161
00:08:55,580 --> 00:08:58,430
What does this serialized field Meet?

162
00:08:58,430 --> 00:09:00,580
Well, don't worry about it.

163
00:09:00,575 --> 00:09:01,415
Later on.

164
00:09:01,415 --> 00:09:05,995
I will also explain why we are using something called a serialized field.

165
00:09:05,990 --> 00:09:11,950
But for now understand that it is something that we can see in the Inspector.

166
00:09:11,945 --> 00:09:14,255
So if I make this public,

167
00:09:14,255 --> 00:09:18,295
save this, go back into our script.

168
00:09:18,290 --> 00:09:21,740
You'll see that in the inspector this changes.

169
00:09:21,740 --> 00:09:23,390
We have the public and movement.

170
00:09:23,390 --> 00:09:24,890
And if we go to the doom player,

171
00:09:24,890 --> 00:09:29,170
you can see right here that we have the movement speed and we can change it.

172
00:09:29,165 --> 00:09:34,915
But if I make it private so that other scripts don't access it,

173
00:09:34,910 --> 00:09:39,970
you'll notice right here that we no longer can change it.

174
00:09:39,965 --> 00:09:44,665
But what if we want to be able to change it from the Inspector,

175
00:09:44,660 --> 00:09:46,450
but at the same time,

176
00:09:46,445 --> 00:09:49,445
we don't want other scripts to access it.

177
00:09:49,445 --> 00:09:51,035
Well, in that case,

178
00:09:51,035 --> 00:09:54,665
we create a serialized field.

179
00:09:54,665 --> 00:09:55,775
We save that.

180
00:09:55,775 --> 00:09:57,325
We go back and do inspector.

181
00:09:57,320 --> 00:09:58,750
And you can see right now,

182
00:09:58,745 --> 00:10:00,605
we can't change it,

183
00:10:00,605 --> 00:10:03,385
but other scripts cannot access it.

184
00:10:03,380 --> 00:10:08,870
We'll look into that later on as we progress when we have other scripts.

185
00:10:08,869 --> 00:10:14,139
Great, so now we have the variable of the movement speed.

186
00:10:14,135 --> 00:10:16,655
The next thing we want to get is d,

187
00:10:16,655 --> 00:10:21,145
movement, direction or the input that we get.

188
00:10:21,140 --> 00:10:24,320
So how are we going to move our player?

189
00:10:24,320 --> 00:10:27,530
Well, we are going to need two inputs.

190
00:10:27,530 --> 00:10:31,460
One which will move the player left and right,

191
00:10:31,460 --> 00:10:33,530
or in the horizontal direction,

192
00:10:33,530 --> 00:10:36,710
and one which will move the player up and down,

193
00:10:36,710 --> 00:10:39,460
which is the vertical direction.

194
00:10:39,455 --> 00:10:44,995
So the way we do that is by using the input system and we're going to

195
00:10:44,990 --> 00:10:50,800
get our inputs using something called the input dot get access Raw.

196
00:10:50,795 --> 00:10:53,375
Now, you might be confused. What is that?

197
00:10:53,375 --> 00:10:55,195
How are we going to get this?

198
00:10:55,190 --> 00:10:59,170
Well, whenever you face some maybe.

199
00:10:59,165 --> 00:11:03,025
Maybe a new method or

200
00:11:03,020 --> 00:11:06,620
some weird thing that we are using in unity and you're a bit confused.

201
00:11:06,620 --> 00:11:10,330
You have a very helpful friend, which is Google.

202
00:11:10,325 --> 00:11:12,655
And then when you look it up in Google,

203
00:11:12,650 --> 00:11:16,030
you can see that we have something called the Unity documentation,

204
00:11:16,025 --> 00:11:22,795
which is such an amazing place and it should be a daily source of information for you.

205
00:11:22,790 --> 00:11:25,220
So we want to use input.

206
00:11:25,220 --> 00:11:26,800
We want to get the axes,

207
00:11:26,795 --> 00:11:29,335
which are the horizontal and vertical.

208
00:11:29,330 --> 00:11:30,590
You can see right here,

209
00:11:30,590 --> 00:11:33,130
if we look for it and the documentations,

210
00:11:33,125 --> 00:11:35,735
we have all the information that we need.

211
00:11:35,735 --> 00:11:39,415
First of all, we can see how the declaration works.

212
00:11:39,410 --> 00:11:42,020
We can see the description so it returns

213
00:11:42,020 --> 00:11:45,740
the value of the virtual access identified by axis name.

214
00:11:45,740 --> 00:11:49,970
It also tells you how to use these different methods.

215
00:11:49,970 --> 00:11:55,660
And also it gives you right here a example of how to use it.

216
00:11:55,655 --> 00:11:57,025
And lo and behold,

217
00:11:57,020 --> 00:11:59,230
they use it and the update,

218
00:11:59,225 --> 00:12:04,085
we can even go ahead and copy this and use it in our own king.

219
00:12:04,085 --> 00:12:07,195
But for now, we're just going to look up the input dot,

220
00:12:07,190 --> 00:12:09,620
get access row, horizontal.

221
00:12:09,620 --> 00:12:13,760
Very nice. But where did they get the horizontal name from?

222
00:12:13,760 --> 00:12:15,140
Let's check it out.

223
00:12:15,140 --> 00:12:17,300
If we go back and our game.

224
00:12:17,300 --> 00:12:24,310
If we go to the file or let me see the Edit Project Settings.

225
00:12:24,305 --> 00:12:28,155
If we look through the input manager,

226
00:12:28,159 --> 00:12:30,279
we click on the axis,

227
00:12:30,275 --> 00:12:32,995
we can see that we have the horizontal,

228
00:12:32,990 --> 00:12:35,870
vertical firewall to jump,

229
00:12:35,870 --> 00:12:38,260
mouseX fire jump, et cetera.

230
00:12:38,255 --> 00:12:41,005
These are all the inputs that we can use.

231
00:12:41,000 --> 00:12:42,770
And if we click on the Horizontal,

232
00:12:42,769 --> 00:12:46,089
you can see right here that we have the name horizontal,

233
00:12:46,085 --> 00:12:49,505
hence why it's being used right here.

234
00:12:49,505 --> 00:12:54,035
Whereas here you can see that we are using horizontal.

235
00:12:54,035 --> 00:12:58,555
And you also have the vertical and you can see the negative button is left,

236
00:12:58,550 --> 00:13:00,370
the positive button is right.

237
00:13:00,365 --> 00:13:04,475
And you also have an out negative button, which means alternative,

238
00:13:04,475 --> 00:13:08,395
which is the a and the D. You also have the gravity and so on,

239
00:13:08,390 --> 00:13:10,160
but of details in there.

240
00:13:10,160 --> 00:13:11,980
And you also have the axis,

241
00:13:11,975 --> 00:13:15,245
the x axis, which means the horizontal.

242
00:13:15,245 --> 00:13:19,055
So let's go ahead in our code and implement this.

243
00:13:19,055 --> 00:13:21,835
So we're going to open up the cold right here.

244
00:13:21,830 --> 00:13:23,350
They used it an update.

245
00:13:23,345 --> 00:13:26,005
Let's go ahead and use it and update because we want to

246
00:13:26,000 --> 00:13:29,290
get access to it every single time.

247
00:13:29,285 --> 00:13:38,215
So we're going to write in here input dot, get access wrong.

248
00:13:38,215 --> 00:13:42,145
And we are going to open up the two brackets in here.

249
00:13:42,145 --> 00:13:45,495
But now we want to write horizontal.

250
00:13:45,490 --> 00:13:48,520
Let's say we write hurry xanthan.

251
00:13:48,520 --> 00:13:51,610
So you can see, I kind of messed it up.

252
00:13:51,610 --> 00:13:53,830
It's not the correct word.

253
00:13:53,830 --> 00:14:00,060
If it's not the exact same word as the one used right here in the Project Settings.

254
00:14:00,055 --> 00:14:01,995
This will not work.

255
00:14:01,990 --> 00:14:03,280
What does that mean?

256
00:14:03,280 --> 00:14:06,790
Whenever we are using the string references,

257
00:14:06,790 --> 00:14:08,880
we already learned what strings are.

258
00:14:08,875 --> 00:14:12,865
We need to make sure that we go into Unity.

259
00:14:12,865 --> 00:14:15,735
Double-click in here to select it,

260
00:14:15,735 --> 00:14:17,815
Control C to copy it,

261
00:14:17,810 --> 00:14:20,350
go back here and paste.

262
00:14:20,345 --> 00:14:24,625
This was assure that we'd not make any mistake whenever

263
00:14:24,620 --> 00:14:28,940
we are creating or using a string reference.

264
00:14:28,940 --> 00:14:32,770
This is very important because when it comes to errors,

265
00:14:32,765 --> 00:14:35,945
this will not be detected by the Visual Studio.

266
00:14:35,945 --> 00:14:41,555
That's why it's imperative whenever you are using a string reference to always,

267
00:14:41,555 --> 00:14:43,675
always copy it and paste.

268
00:14:43,670 --> 00:14:48,100
This is a rule that you will use all your journey game development.

269
00:14:48,095 --> 00:14:52,055
Now that we have the axis roll on horizontal.

270
00:14:52,055 --> 00:14:53,845
We can also add the vertical,

271
00:14:53,840 --> 00:14:55,180
but it's not enough.

272
00:14:55,175 --> 00:14:58,895
We need a way to store what we are clicking.

273
00:14:58,895 --> 00:15:03,245
So the way we do that is we'll create another variable in here.

274
00:15:03,245 --> 00:15:05,585
This time it's going to be private.

275
00:15:05,585 --> 00:15:10,885
It's going to be of type vector 2 and it's going to be the movement.

276
00:15:10,880 --> 00:15:18,140
And now what is a vector two and why we use it in order to have the movement input.

277
00:15:18,140 --> 00:15:24,240
Well, because if we look back in here and wait for it to compile,

278
00:15:24,244 --> 00:15:29,094
you can see that the position is an x, y, and z.

279
00:15:29,090 --> 00:15:34,120
Now, because we are not working in VC dimension and this dimension,

280
00:15:34,115 --> 00:15:35,315
whatever you wanna call it,

281
00:15:35,315 --> 00:15:37,925
we are only working in the x and y.

282
00:15:37,925 --> 00:15:44,135
We want to have a vector to that will take in both the x and the y.

283
00:15:44,135 --> 00:15:46,715
So now what we can do in our code,

284
00:15:46,715 --> 00:15:48,415
we can come here.

285
00:15:48,410 --> 00:15:51,650
We can write movement input.

286
00:15:51,650 --> 00:15:57,050
We can add the dot x and it's going to be equal to the input dot.

287
00:15:57,050 --> 00:15:59,200
Get access wrong.

288
00:15:59,195 --> 00:16:01,825
And just to make sure that we can see everything,

289
00:16:01,820 --> 00:16:05,240
we are going to write debug dot log.

290
00:16:05,240 --> 00:16:08,950
And in here we are just going to print out the movement,

291
00:16:08,945 --> 00:16:11,405
that foot dot x.

292
00:16:11,405 --> 00:16:12,905
We will save that.

293
00:16:12,905 --> 00:16:20,495
Let's also go ahead and print out the debug dot log and the whole movement input.

294
00:16:20,495 --> 00:16:23,855
So I'm going to write in here,

295
00:16:24,490 --> 00:16:28,030
this is the vector.

296
00:16:28,025 --> 00:16:36,415
To save that, go back into Unity and make sure you have the console right here.

297
00:16:36,410 --> 00:16:39,040
If you don't go to Window, go to General.

298
00:16:39,035 --> 00:16:42,035
And you can see right here you have the console window.

299
00:16:42,035 --> 00:16:43,805
So we're going to click on here.

300
00:16:43,805 --> 00:16:46,525
Don't worry about these small errors.

301
00:16:46,520 --> 00:16:48,390
Run the game.

302
00:16:48,390 --> 00:16:52,830
There we go. So we can see that we currently have zeros.

303
00:16:52,825 --> 00:16:54,435
We can click on the collapse.

304
00:16:54,430 --> 00:16:57,540
This will collapse all the messages that are the same.

305
00:16:57,535 --> 00:17:01,065
If we now try to press a or D,

306
00:17:01,060 --> 00:17:03,900
if we press on the a, there you go.

307
00:17:03,895 --> 00:17:10,845
You can see that this becomes minus 1 and vector 2 is minus 1 000.

308
00:17:10,840 --> 00:17:12,550
If we press the d key,

309
00:17:12,550 --> 00:17:18,120
you'll notice that it becomes 1 and the vector two is 110.

310
00:17:18,115 --> 00:17:19,605
So there we go.

311
00:17:19,600 --> 00:17:24,420
Excellent. Now that you understand how these work, how these look,

312
00:17:24,415 --> 00:17:30,435
it's time for a small challenge and your challenge is going to be to get the y input.

313
00:17:30,435 --> 00:17:36,845
So check in Project Settings Input Manager for the y input, what should it be?

314
00:17:36,845 --> 00:17:39,365
What should the string reference me?

315
00:17:39,365 --> 00:17:43,345
Get the input and code using the gap axis roll.

316
00:17:43,340 --> 00:17:48,340
You can also check out something called the get access without row.

317
00:17:48,335 --> 00:17:52,235
This is a good The extra resource for you to do.

318
00:17:52,235 --> 00:17:54,405
It's very easy, just checking the documentation,

319
00:17:54,409 --> 00:17:57,909
the just get access without Rob, see what's difference.

320
00:17:57,905 --> 00:18:04,685
And finally, you will need to display that input on the console using the debug dot log,

321
00:18:04,685 --> 00:18:07,105
just like we did using the movement input.

322
00:18:07,100 --> 00:18:12,300
So pause the video right now and go do the each gallon.

323
00:18:12,295 --> 00:18:14,935
Okay, welcome back.

324
00:18:14,930 --> 00:18:16,790
How did you get on with that?

325
00:18:16,790 --> 00:18:19,610
I always hope that you are trying your best.

326
00:18:19,610 --> 00:18:22,690
So we are going to duplicate this line.

327
00:18:22,685 --> 00:18:25,865
How would we do that? Simply click on the end of this line.

328
00:18:25,865 --> 00:18:27,535
Hold control D.

329
00:18:27,530 --> 00:18:30,460
Now you have the exact same line.

330
00:18:30,455 --> 00:18:34,825
We're going to change this from the x to the y.

331
00:18:34,820 --> 00:18:36,070
There you go.

332
00:18:36,065 --> 00:18:38,485
And then the input.txt get access.

333
00:18:38,480 --> 00:18:40,300
Rob, what should this be?

334
00:18:40,295 --> 00:18:42,325
Well, we know this should be vertical,

335
00:18:42,320 --> 00:18:46,490
but whenever we are dealing with string references,

336
00:18:46,490 --> 00:18:47,840
we go to the vertical,

337
00:18:47,840 --> 00:18:53,840
double-click Control C, go back in the code control V, save that.

338
00:18:53,840 --> 00:18:56,660
And let's duplicate this also,

339
00:18:56,660 --> 00:18:59,430
movement input dot y.

340
00:18:59,434 --> 00:19:03,294
And let's just add a bit of words in here.

341
00:19:03,290 --> 00:19:05,850
So this will be the x,

342
00:19:06,550 --> 00:19:10,620
this will be the y.

343
00:19:10,624 --> 00:19:12,174
Save all of that,

344
00:19:12,170 --> 00:19:13,900
go back into unity.

345
00:19:13,895 --> 00:19:17,105
That's close the project settings window.

346
00:19:17,105 --> 00:19:20,515
Run the game. So now as you can see both the x,

347
00:19:20,510 --> 00:19:23,120
the y, and the vector or all 0.

348
00:19:23,120 --> 00:19:25,190
And you can see how many we have in here.

349
00:19:25,190 --> 00:19:27,350
Once we press the w,

350
00:19:27,350 --> 00:19:29,870
We can see that we have the y as one,

351
00:19:29,870 --> 00:19:32,870
the vector 2, 0, 1.

352
00:19:32,870 --> 00:19:35,520
If we press the S, it's minus1.

353
00:19:35,524 --> 00:19:37,144
If we press the a,

354
00:19:37,145 --> 00:19:40,505
x is minus1 while the y is still 0,

355
00:19:40,505 --> 00:19:42,425
you can see it right here in the vector 2.

356
00:19:42,425 --> 00:19:46,055
If we press both the W and the D key,

357
00:19:46,055 --> 00:19:48,865
you can see that we have this vector is 1,

358
00:19:48,860 --> 00:19:50,830
1 with x being one.

359
00:19:50,825 --> 00:19:55,865
And everything is working perfectly fine with everything.

360
00:19:55,865 --> 00:19:57,385
So I hope you enjoy it.

361
00:19:57,380 --> 00:19:59,500
I hope you understood what's happening.

362
00:19:59,495 --> 00:20:01,955
If you're not sure what's happening.

363
00:20:01,955 --> 00:20:03,845
Tried to look through this again,

364
00:20:03,845 --> 00:20:05,975
understand what a vector two means.

365
00:20:05,975 --> 00:20:08,335
We also have something called the vector 3.

366
00:20:08,330 --> 00:20:10,550
Whenever we are working with VC dimensions,

367
00:20:10,549 --> 00:20:12,129
if it's a 3D game.

368
00:20:12,125 --> 00:20:14,185
And with that said,

369
00:20:14,180 --> 00:20:17,630
I hope you enjoy and hope you also understood how update is being

370
00:20:17,630 --> 00:20:22,250
called every single frame you can see how many times it's being called.

371
00:20:22,250 --> 00:20:24,380
And just for a small demonstration,

372
00:20:24,380 --> 00:20:27,880
if you're still a bit skeptical of what I'm saying,

373
00:20:27,875 --> 00:20:30,625
Let's try debug dot log.

374
00:20:30,620 --> 00:20:33,920
And let's just say in here, hey,

375
00:20:33,920 --> 00:20:39,410
I'm and start being called once.

376
00:20:39,410 --> 00:20:43,850
Saved that back in our game when we run,

377
00:20:43,850 --> 00:20:47,500
as soon as this assembles, run the game.

378
00:20:47,495 --> 00:20:49,355
You'll see right here, hey,

379
00:20:49,355 --> 00:20:51,555
is called only once.

380
00:20:51,559 --> 00:20:54,669
And these are being called every single frame.

381
00:20:54,665 --> 00:20:56,635
And our game with that said,

382
00:20:56,630 --> 00:21:00,910
back in here, commit all of our changes.

383
00:21:00,905 --> 00:21:02,165
Commit.

384
00:21:02,165 --> 00:21:04,825
And what should we call it in here?

385
00:21:04,820 --> 00:21:13,280
Created a script for the player and learned variables.

386
00:21:13,280 --> 00:21:16,640
Now, this is because we are creating a course usually when you're

387
00:21:16,640 --> 00:21:20,350
doing a project and learned variables, isn't that important?

388
00:21:20,345 --> 00:21:21,505
I'm going to remove it.

389
00:21:21,500 --> 00:21:25,460
That's just say created a script for the layer.

390
00:21:25,460 --> 00:21:27,550
We are going to commit our changes.

391
00:21:27,545 --> 00:21:31,355
And I'll see you in the next video.

