1
00:00:00,000 --> 00:00:03,420
Welcome back, My favorite game developers and this video,

2
00:00:03,420 --> 00:00:04,980
when we run the game,

3
00:00:04,980 --> 00:00:07,530
you'll see that we have the rifle.

4
00:00:07,530 --> 00:00:09,570
When we switch a weapon, we have a pistol.

5
00:00:09,570 --> 00:00:10,650
When we switch the weapon,

6
00:00:10,650 --> 00:00:12,300
we have a shotgun.

7
00:00:12,300 --> 00:00:16,430
So now we have a visual representation of which gone,

8
00:00:16,425 --> 00:00:17,945
we are carrying with us.

9
00:00:17,940 --> 00:00:20,120
So without further do,

10
00:00:20,115 --> 00:00:23,645
let's not waste any more time and let's get started.

11
00:00:23,640 --> 00:00:25,530
Oh, case.

12
00:00:25,530 --> 00:00:28,830
So now instead of just changing the gun,

13
00:00:28,830 --> 00:00:31,170
the pillars holding, we want to also

14
00:00:31,170 --> 00:00:34,580
display this on the UI screen that we've created.

15
00:00:34,575 --> 00:00:37,145
So let's go ahead and do that.

16
00:00:37,140 --> 00:00:38,910
First of all, I'm going to make

17
00:00:38,910 --> 00:00:42,340
the scene a little bit bigger so we can see properly,

18
00:00:42,340 --> 00:00:46,610
I'm going to double-click somewhere here on the canvas,

19
00:00:46,610 --> 00:00:48,680
whereas the canvas double-click on it.

20
00:00:48,680 --> 00:00:51,730
And there we go. Now we have the huge canvas.

21
00:00:51,725 --> 00:00:53,755
Let's go to the layers and let's

22
00:00:53,750 --> 00:00:56,990
set that we can see the UI layer.

23
00:00:56,990 --> 00:00:59,210
And in here this just for a moment,

24
00:00:59,210 --> 00:01:03,110
turn off the fading image so we see what is going on.

25
00:01:03,110 --> 00:01:05,360
And in here, what are we going to act?

26
00:01:05,360 --> 00:01:07,340
Well, we want two things to represent

27
00:01:07,340 --> 00:01:09,700
the weapons that we are using at the moment.

28
00:01:09,695 --> 00:01:11,095
We want to have some kind

29
00:01:11,090 --> 00:01:12,740
of image to represent the weapon and

30
00:01:12,740 --> 00:01:16,180
we want some kind of text under that image.

31
00:01:16,175 --> 00:01:18,745
So let's go ahead and get started.

32
00:01:18,740 --> 00:01:22,840
The first thing I'm going to add is right-click in here.

33
00:01:22,835 --> 00:01:24,745
And let's just first of all create

34
00:01:24,740 --> 00:01:26,210
an empty game object just to

35
00:01:26,210 --> 00:01:28,180
represent everything about gun.

36
00:01:28,175 --> 00:01:33,195
So I'm going to say weapons, UI.

37
00:01:33,199 --> 00:01:34,879
And under weapons you are,

38
00:01:34,880 --> 00:01:38,560
I'm going to create a image first of all.

39
00:01:38,555 --> 00:01:43,955
So image, this will be the Weapon Image.

40
00:01:43,955 --> 00:01:45,965
And I'm also going to create

41
00:01:45,965 --> 00:01:50,035
a text which is going to be the work.

42
00:01:50,030 --> 00:01:55,650
What is it, the weapons text.

43
00:01:56,470 --> 00:01:58,750
There we go. So now we have

44
00:01:58,745 --> 00:02:00,865
a weapon image and a weapon text.

45
00:02:00,860 --> 00:02:03,890
I'm going to click on the canvas here for a second.

46
00:02:03,890 --> 00:02:05,330
Just open this up.

47
00:02:05,330 --> 00:02:06,950
By opening up the canvas, I can,

48
00:02:06,950 --> 00:02:09,860
wherever I click, I can still see the borders.

49
00:02:09,860 --> 00:02:11,060
So I'm going to choose

50
00:02:11,060 --> 00:02:14,150
the image and I'm going to drag it down to the side.

51
00:02:14,150 --> 00:02:16,820
And you can see right here in the game view what

52
00:02:16,820 --> 00:02:19,840
we are going to see all the time.

53
00:02:19,835 --> 00:02:23,635
So I'm going to make this a bit bigger,

54
00:02:23,630 --> 00:02:27,050
like something about that size.

55
00:02:27,049 --> 00:02:30,169
And this will be the gun engineer.

56
00:02:30,170 --> 00:02:32,390
And then we will have the texts to

57
00:02:32,390 --> 00:02:34,810
write under it right here.

58
00:02:34,805 --> 00:02:37,225
And let's just test this out and see how it works.

59
00:02:37,220 --> 00:02:39,850
So in the image we will choose a source.

60
00:02:39,845 --> 00:02:42,625
I'm going to lock this down just so we don't lose it.

61
00:02:42,620 --> 00:02:47,420
And I'm going to go into the sprites guns.

62
00:02:47,420 --> 00:02:51,530
And let's go ahead and add the shotgun. So there you go.

63
00:02:51,530 --> 00:02:53,540
You can see now we can see the shotgun.

64
00:02:53,540 --> 00:02:55,310
We can set it to the native size

65
00:02:55,310 --> 00:02:56,920
to make it a bit smaller.

66
00:02:56,915 --> 00:03:00,605
But you know what? I honestly like the way it was before.

67
00:03:00,605 --> 00:03:03,145
Big and easy to see.

68
00:03:03,140 --> 00:03:04,490
Now the weapons text,

69
00:03:04,490 --> 00:03:07,160
we want to change a bit because we want to have this,

70
00:03:07,160 --> 00:03:13,600
for example, the weapons name.

71
00:03:13,595 --> 00:03:16,165
And later on we will learn how we

72
00:03:16,160 --> 00:03:18,770
can change or create our own font.

73
00:03:18,770 --> 00:03:20,600
But for now, let's just keep it as it is

74
00:03:20,600 --> 00:03:22,610
just for the purposes of testing.

75
00:03:22,610 --> 00:03:24,770
We can change the alignment

76
00:03:24,770 --> 00:03:27,110
in here and we can set it in the middle.

77
00:03:27,110 --> 00:03:28,450
We can make it bold.

78
00:03:28,445 --> 00:03:30,865
We can do a lot of stuff with the text,

79
00:03:30,860 --> 00:03:33,710
but one of them is changing the color and making it

80
00:03:33,710 --> 00:03:35,330
completely white so we can see it in

81
00:03:35,330 --> 00:03:37,330
the background, no matter what.

82
00:03:37,325 --> 00:03:40,295
I'm going to make it a bit bigger

83
00:03:40,295 --> 00:03:44,345
so we can increase the size.

84
00:03:44,345 --> 00:03:46,585
There you go, you can see that's how we increase

85
00:03:46,580 --> 00:03:50,050
the size and now we will increase the font size.

86
00:03:50,045 --> 00:03:52,675
So there you go.

87
00:03:52,670 --> 00:03:56,150
That is about how I wanted to make it.

88
00:03:56,150 --> 00:03:58,010
So the weapons name right

89
00:03:58,010 --> 00:04:00,680
under the actual weapon and we can even make

90
00:04:00,680 --> 00:04:05,410
the box a bit bigger and increase the size of the words.

91
00:04:05,405 --> 00:04:07,165
So there you go. Now we can

92
00:04:07,160 --> 00:04:09,820
write the shotgun and so on and so forth.

93
00:04:09,815 --> 00:04:11,845
Let's remove the wreck as target

94
00:04:11,840 --> 00:04:13,780
in here because we recurse target,

95
00:04:13,775 --> 00:04:15,415
as we've said, we can click on it.

96
00:04:15,410 --> 00:04:16,630
We don't want to click on it.

97
00:04:16,625 --> 00:04:18,205
It won't make any difference,

98
00:04:18,200 --> 00:04:19,970
but let's just keep it at that.

99
00:04:19,970 --> 00:04:22,040
We can change the horizontal overflow,

100
00:04:22,040 --> 00:04:23,810
the vertical overflow, and we

101
00:04:23,810 --> 00:04:25,810
can create something called the best-fit.

102
00:04:25,805 --> 00:04:28,825
And this is really nice because now when we change,

103
00:04:28,820 --> 00:04:32,030
you can see that the font will change with the,

104
00:04:32,030 --> 00:04:39,200
or the, the size of the words will fit as to as big V.

105
00:04:39,200 --> 00:04:42,230
And I'm not sure why I can say anything properly,

106
00:04:42,230 --> 00:04:43,940
but anyways, there you go.

107
00:04:43,940 --> 00:04:45,620
You understand what I mean by best fit?

108
00:04:45,620 --> 00:04:46,880
You just saw what happens.

109
00:04:46,880 --> 00:04:50,560
Okay, Let's continue on and stop rambling.

110
00:04:50,555 --> 00:04:52,825
The next thing we want to do is we want to have

111
00:04:52,820 --> 00:04:56,750
access or to the behavior of this UI.

112
00:04:56,750 --> 00:04:58,420
So what we're going to do,

113
00:04:58,415 --> 00:05:00,095
we want to first of all,

114
00:05:00,095 --> 00:05:05,465
assigned to each weapon the appropriate sprite and name.

115
00:05:05,465 --> 00:05:09,305
So I'm going to go into the weapons prefab.

116
00:05:09,304 --> 00:05:13,894
So prefabs, weapons, select the pistol.

117
00:05:13,895 --> 00:05:16,835
And this is where we are going to be setting everything.

118
00:05:16,835 --> 00:05:20,645
So I'm going to open up the script right here.

119
00:05:20,645 --> 00:05:22,585
And on the weapon system,

120
00:05:22,580 --> 00:05:24,670
because each one has a weapon system,

121
00:05:24,665 --> 00:05:27,715
we are going to add two variables.

122
00:05:27,710 --> 00:05:32,840
The first one is going to be a sprite.

123
00:05:32,840 --> 00:05:36,890
And it's going to be the gun image.

124
00:05:36,890 --> 00:05:40,470
And the second one is going to be a string.

125
00:05:40,474 --> 00:05:44,044
And it's going to be the gun.

126
00:05:44,045 --> 00:05:45,595
Let's keep it.

127
00:05:45,590 --> 00:05:49,700
A weapon and the weapon.

128
00:05:49,700 --> 00:05:52,870
Weapon, neck. There we go.

129
00:05:52,865 --> 00:05:56,785
So weapon Text, Weapon Image and what happened name.

130
00:05:56,780 --> 00:05:58,700
And if I go back into

131
00:05:58,700 --> 00:06:01,400
Unity after it compiles, There we go.

132
00:06:01,400 --> 00:06:04,340
We can see that we have the image sprite and image name.

133
00:06:04,340 --> 00:06:06,410
So we're going to choose the pistol.

134
00:06:06,410 --> 00:06:09,940
Go to the pistol at the image.

135
00:06:09,935 --> 00:06:14,015
Make this the stone.

136
00:06:14,290 --> 00:06:20,150
And then we are going to go and to the rifle or

137
00:06:20,150 --> 00:06:25,580
nano to go back to the Prefabs weapons rifle,

138
00:06:25,580 --> 00:06:29,870
lock this down, find the image down here.

139
00:06:29,870 --> 00:06:31,400
What's the name?

140
00:06:31,400 --> 00:06:35,440
Let's just keep it at rifle without the assault part.

141
00:06:35,435 --> 00:06:38,405
And what else do we have?

142
00:06:38,404 --> 00:06:40,294
Less choose the shotgun,

143
00:06:40,295 --> 00:06:45,125
know that the prefab shot gun, lock this down.

144
00:06:45,580 --> 00:06:49,130
Finally, shotgun image, green here,

145
00:06:49,130 --> 00:06:53,180
weapons name, shocked, gun. There we go.

146
00:06:53,180 --> 00:06:55,360
So now each prefab has

147
00:06:55,355 --> 00:06:57,745
its own garden image or

148
00:06:57,740 --> 00:07:00,310
Weapon Image and its own weapon neck.

149
00:07:00,305 --> 00:07:03,865
So next thing we need to do is we need two every single

150
00:07:03,860 --> 00:07:07,390
time we change a weapon to fill this image.

151
00:07:07,385 --> 00:07:10,025
Currently, if I run the game,

152
00:07:10,025 --> 00:07:12,415
you'll notice that I have

153
00:07:12,410 --> 00:07:14,090
the image right here, I can move around,

154
00:07:14,090 --> 00:07:15,920
but if I tried to change my weapon,

155
00:07:15,920 --> 00:07:17,510
the images don't change.

156
00:07:17,510 --> 00:07:21,040
So now it's time to add behavior to this.

157
00:07:21,035 --> 00:07:24,565
And we are going to do that in the UI Manager,

158
00:07:24,560 --> 00:07:26,260
which is on the campus.

159
00:07:26,255 --> 00:07:28,885
So let's open up the UI Manager

160
00:07:28,880 --> 00:07:31,700
and let's see what are we going to do in here.

161
00:07:31,700 --> 00:07:34,180
So first thing first is we need

162
00:07:34,175 --> 00:07:36,865
a reference to both the image and the text.

163
00:07:36,860 --> 00:07:40,820
So I'm going to create a serialized fields in here,

164
00:07:40,820 --> 00:07:43,210
which is going to be of type image.

165
00:07:43,205 --> 00:07:44,905
And we can use EMG because we have

166
00:07:44,900 --> 00:07:48,470
Unity engine dot QI using up there.

167
00:07:48,470 --> 00:07:52,610
We are going to call this the weapon image.

168
00:07:52,610 --> 00:07:54,200
Let's just keep things simple,

169
00:07:54,200 --> 00:07:56,380
just like they were before.

170
00:07:56,375 --> 00:07:59,005
And in here we will have a text with which

171
00:07:59,000 --> 00:08:02,690
is the weapon name.

172
00:08:02,690 --> 00:08:05,540
Save that back in Unity.

173
00:08:05,540 --> 00:08:10,450
And let's see now we can go ahead and lock this down.

174
00:08:10,445 --> 00:08:13,085
And we can add the weapon image,

175
00:08:13,085 --> 00:08:15,305
and we can add the weapons tax.

176
00:08:15,305 --> 00:08:18,245
We can click on the UI canvas and make sure we

177
00:08:18,245 --> 00:08:21,825
apply these changes all over our project.

178
00:08:21,829 --> 00:08:22,399
Excellent.

179
00:08:22,400 --> 00:08:26,440
Now, the next thing to do is to show you a challenge.

180
00:08:26,435 --> 00:08:28,045
And your challenge is going to be to

181
00:08:28,040 --> 00:08:30,650
create a method that changes the gut.

182
00:08:30,650 --> 00:08:32,150
So first thing first,

183
00:08:32,150 --> 00:08:34,630
you need to create a void method that

184
00:08:34,625 --> 00:08:37,975
is public and takes two parameters.

185
00:08:37,970 --> 00:08:41,030
An image for the gun and a string for

186
00:08:41,030 --> 00:08:42,290
the gun name or

187
00:08:42,290 --> 00:08:44,650
weapons name or whatever you wanna call it.

188
00:08:44,645 --> 00:08:46,015
Then you'll need to set

189
00:08:46,010 --> 00:08:48,580
the gun UI sprite using the image.

190
00:08:48,575 --> 00:08:50,185
And you'll also need to set

191
00:08:50,180 --> 00:08:53,230
the gun name text as the column name.

192
00:08:53,225 --> 00:08:56,395
And finally, I will give you a small hint if you want,

193
00:08:56,390 --> 00:08:58,480
if you don't and do the challenge.

194
00:08:58,475 --> 00:09:01,375
If not, you can use the gun you I dot

195
00:09:01,370 --> 00:09:04,730
sprite and the gun UI or gun name you are,

196
00:09:04,730 --> 00:09:08,140
or whatever the name of the actual variable was.

197
00:09:08,135 --> 00:09:12,505
Dot text, dot sprite to access the sprite and the text.

198
00:09:12,500 --> 00:09:15,920
Remember this should be weapon and not UI image.

199
00:09:15,920 --> 00:09:18,440
Oh, okay, so there you go.

200
00:09:18,440 --> 00:09:20,170
Pause the video right now.

201
00:09:20,165 --> 00:09:23,735
Go do the Chaldean.

202
00:09:23,890 --> 00:09:26,090
Okay, welcome back.

203
00:09:26,090 --> 00:09:28,960
So what are we going to do in here?

204
00:09:28,955 --> 00:09:34,285
And we are going to create a public void and

205
00:09:34,280 --> 00:09:42,610
change gone or change Open UI.

206
00:09:42,605 --> 00:09:45,685
And we said that we are going to take in two parameters.

207
00:09:45,680 --> 00:09:49,090
The first parameter is going to be a sprite,

208
00:09:49,085 --> 00:09:54,545
and it's going to be the weapons image.

209
00:09:54,545 --> 00:09:56,545
And know what, because we already

210
00:09:56,540 --> 00:09:58,760
have the weapon image year.

211
00:09:58,760 --> 00:10:01,060
Let's change this one to gun.

212
00:10:01,055 --> 00:10:03,235
So there you go, gun image.

213
00:10:03,230 --> 00:10:05,920
And we're going to also take in a string,

214
00:10:05,915 --> 00:10:08,995
which is going to be the gun text.

215
00:10:08,990 --> 00:10:11,780
So these are the two parameters that we are

216
00:10:11,780 --> 00:10:14,260
going to create and now that we have them,

217
00:10:14,255 --> 00:10:17,045
how are we going to change the images?

218
00:10:17,045 --> 00:10:18,905
While if we go in here,

219
00:10:18,905 --> 00:10:20,915
as I've told you in the hands,

220
00:10:20,915 --> 00:10:22,405
if we click on the weapon image,

221
00:10:22,400 --> 00:10:25,450
we can see that right here we have the source image.

222
00:10:25,445 --> 00:10:29,485
So if I go, I'm going to say that we have

223
00:10:29,480 --> 00:10:34,120
the Weapon Image Sprite

224
00:10:34,115 --> 00:10:39,575
and it's equal to the gun image that was provided to us.

225
00:10:39,575 --> 00:10:45,895
And then we have the weapon name dot text.

226
00:10:45,890 --> 00:10:47,690
So we are accessing.

227
00:10:47,690 --> 00:10:50,920
Let me go back in here and show you something.

228
00:10:50,915 --> 00:10:52,985
So we have the weapons relaxed.

229
00:10:52,985 --> 00:10:55,825
It is of type text but the component tax,

230
00:10:55,820 --> 00:10:58,910
but we are accessing the text on the text.

231
00:10:58,910 --> 00:11:03,290
So we have this text parameter or characteristic.

232
00:11:03,290 --> 00:11:06,260
The components. So we are accessing that by saying

233
00:11:06,260 --> 00:11:11,270
dot txt and it's equal to the gun text.

234
00:11:11,270 --> 00:11:12,700
Save that.

235
00:11:12,695 --> 00:11:14,425
Oh, great.

236
00:11:14,420 --> 00:11:17,500
Now we can actually change the UI,

237
00:11:17,495 --> 00:11:20,845
but the next step is to actually change

238
00:11:20,840 --> 00:11:25,120
the UI of the weapons whenever we switch them.

239
00:11:25,115 --> 00:11:27,505
And where are we going to do that?

240
00:11:27,500 --> 00:11:29,660
Well, we are going to do that in

241
00:11:29,660 --> 00:11:32,810
the switch weapon method 0 and 0.

242
00:11:32,810 --> 00:11:34,730
There is something here I wanted

243
00:11:34,730 --> 00:11:37,280
to tell you, I commented out.

244
00:11:37,280 --> 00:11:39,280
Let me tell you right now,

245
00:11:39,275 --> 00:11:42,925
if you've noticed when we play our game,

246
00:11:42,920 --> 00:11:44,270
as soon as we start,

247
00:11:44,270 --> 00:11:46,250
for example, we have the rifle, okay,

248
00:11:46,250 --> 00:11:49,870
so we hit the tab key and it doesn't change,

249
00:11:49,865 --> 00:11:52,375
not until we hit the tab key again.

250
00:11:52,370 --> 00:11:53,810
So what is the problem?

251
00:11:53,810 --> 00:11:56,140
The problem is that in

252
00:11:56,135 --> 00:12:00,175
our layer right here we can see we have the current gone,

253
00:12:00,170 --> 00:12:02,500
but we haven't assigned any value to it.

254
00:12:02,495 --> 00:12:04,595
So it doesn't know what the value is.

255
00:12:04,595 --> 00:12:08,255
So what I did and start and the player controller,

256
00:12:08,254 --> 00:12:11,274
we can simply write these two lines of code.

257
00:12:11,270 --> 00:12:13,340
And what these do is first of all,

258
00:12:13,340 --> 00:12:14,980
we set the current gun,

259
00:12:14,975 --> 00:12:18,725
which is an integer to the available weapon dot count,

260
00:12:18,725 --> 00:12:20,615
and then we just switch to the gun.

261
00:12:20,615 --> 00:12:22,465
So we start off at the rifle.

262
00:12:22,460 --> 00:12:24,820
So now when I run the game,

263
00:12:24,815 --> 00:12:27,505
or we can even something much better if you

264
00:12:27,500 --> 00:12:29,740
want to start off with the first weapon that we have.

265
00:12:29,735 --> 00:12:31,195
We can set this as the

266
00:12:31,190 --> 00:12:33,860
available weapons dot count minus one.

267
00:12:33,860 --> 00:12:36,020
So now, as soon as we start the game,

268
00:12:36,020 --> 00:12:39,220
we will have the first gun with us.

269
00:12:39,215 --> 00:12:40,585
Okay, so there we go.

270
00:12:40,580 --> 00:12:42,320
Now we can switch immediately

271
00:12:42,319 --> 00:12:44,209
and there's something wrong here.

272
00:12:44,210 --> 00:12:47,300
Oh, okay, so again, it's that annoying error.

273
00:12:47,300 --> 00:12:48,140
So back in games.

274
00:12:48,140 --> 00:12:50,990
So as you can see now, as soon as we start,

275
00:12:50,990 --> 00:12:53,070
we can hit the Tab.

276
00:13:47,710 --> 00:13:50,380
May want to make this public,

277
00:13:50,375 --> 00:13:52,805
but as I've told you in the previous video,

278
00:13:52,805 --> 00:13:57,415
it's not that good of a way to get access to variables.

279
00:13:57,410 --> 00:13:59,480
A much better way is to go in

280
00:13:59,480 --> 00:14:02,480
here and create two methods.

281
00:14:02,480 --> 00:14:04,690
The first one is going to be a public.

282
00:14:04,685 --> 00:14:07,735
It will return a sprite is going to be

283
00:14:07,730 --> 00:14:11,970
called the get gun image.

284
00:14:11,974 --> 00:14:20,004
You get weapons image actually get the weapon image UI.

285
00:14:20,000 --> 00:14:22,450
And I'm going to open up the brackets and

286
00:14:22,445 --> 00:14:24,875
I'm going to simply return

287
00:14:24,875 --> 00:14:30,155
the weapons and close it off with a semicolon.

288
00:14:30,155 --> 00:14:32,195
And then I'm going to create

289
00:14:32,194 --> 00:14:34,824
a similar method which is going to

290
00:14:34,820 --> 00:14:39,970
return a string and it's going to be getting the weapon.

291
00:14:39,965 --> 00:14:43,975
Get weapon, text, UI or name,

292
00:14:43,970 --> 00:14:46,450
actually name UI or not.

293
00:14:46,445 --> 00:14:49,025
We can't even Use the word UI.

294
00:14:49,025 --> 00:14:50,785
But let's keep it just for the sake

295
00:14:50,780 --> 00:14:53,770
of knowing why we are getting these.

296
00:14:53,765 --> 00:14:56,345
So weapon name, save that.

297
00:14:56,345 --> 00:14:59,575
So now we can access the weapons system.

298
00:14:59,570 --> 00:15:01,250
And from that weapon system we

299
00:15:01,250 --> 00:15:03,280
can access these two methods.

300
00:15:03,275 --> 00:15:04,765
And with these two methods,

301
00:15:04,760 --> 00:15:06,860
we can have the image and the name

302
00:15:06,860 --> 00:15:09,050
of the guns without facing

303
00:15:09,050 --> 00:15:11,150
the problem of changing

304
00:15:11,150 --> 00:15:14,660
these variables by mistake or causing some sort of error.

305
00:15:14,660 --> 00:15:16,970
So right now what we can do is

306
00:15:16,970 --> 00:15:20,030
we can get the available gun.

307
00:15:20,030 --> 00:15:24,640
Available weapon at the position current gun

308
00:15:24,635 --> 00:15:27,205
or is it the current gun?

309
00:15:27,200 --> 00:15:32,320
And we can get the component on this current gun,

310
00:15:32,315 --> 00:15:35,165
which is obviously the weapons system.

311
00:15:35,165 --> 00:15:36,905
And from this weapon system,

312
00:15:36,905 --> 00:15:38,735
we can, what can we do?

313
00:15:38,735 --> 00:15:42,745
We can first of all get what is it called?

314
00:15:42,740 --> 00:15:44,950
Get Weapon Image.

315
00:15:44,945 --> 00:15:48,035
And then we can

316
00:15:48,035 --> 00:15:51,865
hit Enter here because the line is too long.

317
00:15:51,860 --> 00:15:53,720
At a comma.

318
00:15:53,720 --> 00:16:01,790
Copy this, and paste it in here at inaugural enter.

319
00:16:01,790 --> 00:16:04,460
And what seems to be the problem here?

320
00:16:04,460 --> 00:16:06,500
Why is the first one telling me cannot

321
00:16:06,500 --> 00:16:09,230
convert method group 2, right?

322
00:16:09,230 --> 00:16:10,820
Okay. Okay.

323
00:16:10,820 --> 00:16:12,530
This is a method.

324
00:16:12,530 --> 00:16:14,960
And get the name,

325
00:16:14,960 --> 00:16:16,480
get weapon name UI.

326
00:16:16,475 --> 00:16:18,355
There we go. We save that.

327
00:16:18,350 --> 00:16:21,000
So now if you'd like,

328
00:16:21,004 --> 00:16:22,584
I do recommend that we do

329
00:16:22,580 --> 00:16:24,740
something here because we have redundant code.

330
00:16:24,740 --> 00:16:26,000
We can set this as

331
00:16:26,000 --> 00:16:28,690
a variable and then use the Get weapon and get an image.

332
00:16:28,685 --> 00:16:31,285
That would be something smarter to do.

333
00:16:31,280 --> 00:16:33,440
But for now, let's just keep it so we always know

334
00:16:33,440 --> 00:16:36,020
what's happening after we change the weapon,

335
00:16:36,020 --> 00:16:37,340
we set it to true,

336
00:16:37,340 --> 00:16:39,370
then we access the UI Manager.

337
00:16:39,365 --> 00:16:41,845
We get the available weapon at the current position,

338
00:16:41,840 --> 00:16:43,640
we get the weapon systems script

339
00:16:43,640 --> 00:16:45,620
and then we get the weapons image.

340
00:16:45,620 --> 00:16:47,990
We send it to the change Open UI,

341
00:16:47,990 --> 00:16:49,780
which is in the UI Manager.

342
00:16:49,775 --> 00:16:51,725
And this should change

343
00:16:51,725 --> 00:16:54,275
the image whenever we change the gun.

344
00:16:54,275 --> 00:16:56,315
So back in our game,

345
00:16:56,315 --> 00:17:00,715
Let's run and see what happens. There you go.

346
00:17:00,710 --> 00:17:02,600
When we hit Tab, we get the shot gun,

347
00:17:02,600 --> 00:17:03,680
we get the rifle,

348
00:17:03,680 --> 00:17:07,160
we get the pistol which is smashed for

349
00:17:07,160 --> 00:17:08,930
some reason because the pistol

350
00:17:08,930 --> 00:17:10,790
is trying to fill the entire gap.

351
00:17:10,790 --> 00:17:12,530
Let's see, where is it,

352
00:17:12,530 --> 00:17:14,480
where is it? Where is it?

353
00:17:14,480 --> 00:17:17,350
In the UI, the weapon image.

354
00:17:17,345 --> 00:17:20,165
So obviously when we set it as the gun,

355
00:17:20,165 --> 00:17:22,295
it's not that good,

356
00:17:22,295 --> 00:17:23,575
but no worries about that.

357
00:17:23,570 --> 00:17:25,010
As long as it works for you,

358
00:17:25,010 --> 00:17:27,580
we can change this, make it smaller, make it bigger.

359
00:17:27,575 --> 00:17:29,635
Maybe even a better idea,

360
00:17:29,630 --> 00:17:33,130
maybe changed the way this image is represented.

361
00:17:33,125 --> 00:17:34,925
Bother me too much.

362
00:17:34,925 --> 00:17:36,355
If it bothers you,

363
00:17:36,350 --> 00:17:38,150
and I do recommend maybe we'll

364
00:17:38,150 --> 00:17:40,220
see how we can fix this later on.

365
00:17:40,220 --> 00:17:43,160
But for now we can see that it is working.

366
00:17:43,160 --> 00:17:45,110
The only thing that is not working.

367
00:17:45,110 --> 00:17:46,820
As, as soon as we run.

368
00:17:46,820 --> 00:17:49,640
We can see that unless we switch the gun,

369
00:17:49,640 --> 00:17:53,840
we have the first one which is the weapons name,

370
00:17:53,840 --> 00:17:57,290
just like that, a blank image and a blank text.

371
00:17:57,290 --> 00:18:01,360
So what we can do is in UI Manager in here.

372
00:18:01,355 --> 00:18:04,295
So I'm going to select this.

373
00:18:04,295 --> 00:18:07,685
I'm going to right-click quick action and refactoring.

374
00:18:07,685 --> 00:18:13,745
And I'm going to call this the setting weapons.

375
00:18:14,050 --> 00:18:19,120
Weapons. You, I hit Enter.

376
00:18:19,115 --> 00:18:21,555
And now I can go and start.

377
00:18:21,559 --> 00:18:25,149
I'm not going to switch the gun because I just noticed

378
00:18:25,145 --> 00:18:28,955
something that this does not work unless we have the tab.

379
00:18:28,955 --> 00:18:30,595
So all that we're doing in here

380
00:18:30,590 --> 00:18:32,450
is just setting the current gone to,

381
00:18:32,450 --> 00:18:34,040
to have it work immediately.

382
00:18:34,040 --> 00:18:36,160
You can set it to 0 if you want.

383
00:18:36,155 --> 00:18:38,245
But let's remove this and instead

384
00:18:38,240 --> 00:18:40,760
we are going to be setting weapons UI.

385
00:18:40,760 --> 00:18:43,900
So setting weapons you.

386
00:18:43,895 --> 00:18:46,135
As soon as we start.

387
00:18:46,130 --> 00:18:48,890
And let me just select those and hit

388
00:18:48,890 --> 00:18:51,020
Shift tab a couple of times

389
00:18:51,020 --> 00:18:53,350
just to make them looking a bit better.

390
00:18:53,345 --> 00:18:54,985
We save that as I've told you,

391
00:18:54,980 --> 00:18:57,440
the smart thing to do is to change this

392
00:18:57,440 --> 00:19:00,290
and put it in one of the variables.

393
00:19:00,290 --> 00:19:02,450
I recommend you can go do that.

394
00:19:02,450 --> 00:19:04,280
And with all of that set,

395
00:19:04,280 --> 00:19:06,890
Let's go back into our game and let's test this out,

396
00:19:06,890 --> 00:19:09,170
see if it works from the game.

397
00:19:09,170 --> 00:19:14,500
And nope, that didn't help at first.

398
00:19:14,495 --> 00:19:16,205
Why is that?

399
00:19:16,205 --> 00:19:19,215
So after doing a bit of research,

400
00:19:19,219 --> 00:19:21,459
I realized something and

401
00:19:21,455 --> 00:19:23,915
understood where the problem is coming from.

402
00:19:23,915 --> 00:19:27,635
So in here we are trying to set the weapons UI,

403
00:19:27,635 --> 00:19:29,285
which is here, and we're trying to

404
00:19:29,285 --> 00:19:31,495
access the UI Manager Don instance.

405
00:19:31,490 --> 00:19:34,330
The problem is, and I've noticed that right here,

406
00:19:34,325 --> 00:19:36,565
if I run the game,

407
00:19:36,560 --> 00:19:40,310
you'll notice that I have this arrow right here.

408
00:19:40,310 --> 00:19:42,140
And you can see that it object

409
00:19:42,140 --> 00:19:45,230
reference not set as an instance of an object.

410
00:19:45,230 --> 00:19:47,900
So I double-clicked and I looked in here

411
00:19:47,900 --> 00:19:50,590
and I noticed that for some reason

412
00:19:50,585 --> 00:19:54,715
the player script is being instantiated or a

413
00:19:54,710 --> 00:19:58,990
starting before the UI script is starting.

414
00:19:58,985 --> 00:20:04,265
So we still don't have a reference to the UI Manager.

415
00:20:04,265 --> 00:20:06,925
Now, what we can do is we can try

416
00:20:06,920 --> 00:20:09,850
to make this and awake instead

417
00:20:09,845 --> 00:20:12,595
of of a start and

418
00:20:12,590 --> 00:20:16,240
await starts just a little bit earlier than the start.

419
00:20:16,235 --> 00:20:18,185
Let's test this out and see if it works.

420
00:20:18,185 --> 00:20:21,545
If it does, then we saved ourselves a lot of problem.

421
00:20:21,545 --> 00:20:23,725
I'm not sure this would work,

422
00:20:23,720 --> 00:20:25,100
but let's test it out.

423
00:20:25,100 --> 00:20:27,680
So in-game, run the game.

424
00:20:27,680 --> 00:20:28,900
Okay, so there we go.

425
00:20:28,895 --> 00:20:30,925
It did work. How cool is that?

426
00:20:30,920 --> 00:20:32,510
Who we saved so much time,

427
00:20:32,510 --> 00:20:34,090
I wasn't sure it will work.

428
00:20:34,085 --> 00:20:36,965
Now another thing is the pistol being smushed.

429
00:20:36,965 --> 00:20:39,415
We can go into the image right here and make

430
00:20:39,410 --> 00:20:42,170
sure to click on the preserve aspect.

431
00:20:42,170 --> 00:20:44,290
You can see the pistol will stay the same.

432
00:20:44,285 --> 00:20:46,595
So I'll stop the game and Presets,

433
00:20:46,595 --> 00:20:50,875
save that and make sure to apply the changes.

434
00:20:50,870 --> 00:20:54,230
So now when we run, there you go.

435
00:20:54,230 --> 00:20:57,200
You can see that the PESTEL is set correctly,

436
00:20:57,200 --> 00:20:59,000
but what's the problem?

437
00:20:59,000 --> 00:21:00,880
The problem is that I have

438
00:21:00,875 --> 00:21:04,925
a rifle and my hand yet the pistol is being depicted.

439
00:21:04,925 --> 00:21:06,175
Why is that?

440
00:21:06,170 --> 00:21:10,130
Well, because again, if we go back, we'll save that.

441
00:21:10,130 --> 00:21:13,070
And for future purposes,

442
00:21:13,070 --> 00:21:14,180
always make sure to set

443
00:21:14,180 --> 00:21:16,730
the instance and the awake not in the start.

444
00:21:16,730 --> 00:21:19,520
So now this was an amazing opportunity for you to

445
00:21:19,520 --> 00:21:21,530
understand the difference between

446
00:21:21,530 --> 00:21:23,000
the start and the awake.

447
00:21:23,000 --> 00:21:26,300
Awake start just a little bit before we start.

448
00:21:26,300 --> 00:21:28,070
Let's continue one, why do

449
00:21:28,070 --> 00:21:29,740
we have the pistol in the beginning?

450
00:21:29,735 --> 00:21:33,205
It's all because of the current gone available.

451
00:21:33,200 --> 00:21:36,800
So the current gun is being set to dot count minus one,

452
00:21:36,800 --> 00:21:39,050
which is the pistol.

453
00:21:39,049 --> 00:21:42,169
Because the pistol, as you can see in the dooms player,

454
00:21:42,170 --> 00:21:44,330
is the count minus one,

455
00:21:44,330 --> 00:21:45,650
which means element two.

456
00:21:45,650 --> 00:21:48,350
So how are we going to fix this?

457
00:21:48,350 --> 00:21:51,670
Well, what we can do is two things.

458
00:21:51,665 --> 00:21:56,605
We will simply set the current gun to be.

459
00:21:56,600 --> 00:21:59,080
I think maybe one.

460
00:21:59,075 --> 00:22:02,185
That way we will start off on the right position.

461
00:22:02,180 --> 00:22:03,530
So back in here,

462
00:22:03,530 --> 00:22:04,960
we will run the game.

463
00:22:04,955 --> 00:22:08,575
We are holding a rifle and we have a rifle represented.

464
00:22:08,570 --> 00:22:10,060
And so later on,

465
00:22:10,055 --> 00:22:13,115
I'm sure we will find a smarter solution to this,

466
00:22:13,115 --> 00:22:15,455
but for now, we'll just make what works.

467
00:22:15,455 --> 00:22:16,865
I hope you enjoyed the video.

468
00:22:16,865 --> 00:22:19,015
I hope you are saying

469
00:22:19,010 --> 00:22:22,830
all your files and I'll see you in the next one.

