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

2
00:00:03,300 --> 00:00:05,760
I know this is a long video,

3
00:00:05,760 --> 00:00:07,560
but we do a lot of things.

4
00:00:07,560 --> 00:00:11,130
We learn a lot of nifty small tricks in here.

5
00:00:11,130 --> 00:00:12,860
So when we run the game,

6
00:00:12,855 --> 00:00:14,285
you'll notice that we have only

7
00:00:14,280 --> 00:00:15,690
the pistil right now and the

8
00:00:15,690 --> 00:00:18,570
weapons arm we should the pistol, everything works fine.

9
00:00:18,570 --> 00:00:20,390
We have the shotgun on the ground.

10
00:00:20,385 --> 00:00:22,955
Uw, what do you think will happen when we pick it up?

11
00:00:22,950 --> 00:00:24,390
So I headed I pick it up.

12
00:00:24,390 --> 00:00:24,990
There we go.

13
00:00:24,990 --> 00:00:27,150
We can see that I have a shotgun

14
00:00:27,150 --> 00:00:29,400
and we can see the bullet of that shot gun.

15
00:00:29,400 --> 00:00:31,320
We can't switch off anything.

16
00:00:31,320 --> 00:00:34,220
We can switch between the pistol and the shotgun,

17
00:00:34,215 --> 00:00:36,125
but let's not worry about that.

18
00:00:36,120 --> 00:00:37,350
Everything will happen.

19
00:00:37,350 --> 00:00:39,210
Everything will be fixed in due time.

20
00:00:39,210 --> 00:00:41,040
So let's not waste any more time with

21
00:00:41,040 --> 00:00:45,130
this big long video and let's get started.

22
00:00:45,125 --> 00:00:46,875
Oh, case.

23
00:00:46,870 --> 00:00:51,430
So time to set up the way we pick up our weapons.

24
00:00:51,425 --> 00:00:55,855
So right now, the way we have our weapons is good enough.

25
00:00:55,850 --> 00:00:57,530
We are switching, we are doing everything,

26
00:00:57,530 --> 00:01:00,140
but this is not how we want our game to work.

27
00:01:00,140 --> 00:01:02,720
We don't want to just start off with all

28
00:01:02,720 --> 00:01:05,390
of our buttons and just switch between them.

29
00:01:05,390 --> 00:01:08,090
We want to have some kind of mechanics that allows us

30
00:01:08,090 --> 00:01:11,620
to have them or acquired them in some way.

31
00:01:11,615 --> 00:01:14,315
And one of those things is we can pick up

32
00:01:14,315 --> 00:01:17,305
our weapons at certain points and the level.

33
00:01:17,300 --> 00:01:19,370
So let's go ahead and do that.

34
00:01:19,370 --> 00:01:21,470
The first thing that we are going to do

35
00:01:21,470 --> 00:01:24,070
is we're going to go into the doom player.

36
00:01:24,065 --> 00:01:25,435
We're going to remove

37
00:01:25,430 --> 00:01:27,310
the weapons that we are not holding.

38
00:01:27,305 --> 00:01:29,545
So I'm going to remove the rifle,

39
00:01:29,540 --> 00:01:31,180
will need to open up the script.

40
00:01:31,175 --> 00:01:34,315
So remove the rifle, remove the pistol,

41
00:01:34,310 --> 00:01:38,590
and go back into our game. There we go.

42
00:01:38,585 --> 00:01:41,435
Now one thing that we need to make sure of is that we

43
00:01:41,435 --> 00:01:44,945
also remove them from the available weapons right here.

44
00:01:44,945 --> 00:01:48,745
So I'm going to remove these empty slots,

45
00:01:48,740 --> 00:01:52,270
save that, and let's see what we have in here.

46
00:01:52,265 --> 00:01:53,545
Okay, so as you can see,

47
00:01:53,540 --> 00:01:55,370
this is also something that we will

48
00:01:55,370 --> 00:01:57,560
need to change and I'll tell you why.

49
00:01:57,560 --> 00:01:59,180
Let's just get things out of the way.

50
00:01:59,180 --> 00:02:00,650
So currently we are setting

51
00:02:00,650 --> 00:02:04,090
the current gun at one and then setting the weapon UI,

52
00:02:04,085 --> 00:02:07,805
but one isn't available right here.

53
00:02:07,805 --> 00:02:11,425
So let's see what happens when we run our game.

54
00:02:11,420 --> 00:02:14,360
We should see that we have an arrow right here,

55
00:02:14,360 --> 00:02:17,260
and this error is argument out of range.

56
00:02:17,255 --> 00:02:18,535
I double-click in here,

57
00:02:18,530 --> 00:02:20,930
it takes me to the setting weapon.

58
00:02:20,930 --> 00:02:23,120
That means the current gun is out

59
00:02:23,120 --> 00:02:25,420
of range inside of the available weapons.

60
00:02:25,415 --> 00:02:26,815
And of course it is because

61
00:02:26,810 --> 00:02:28,250
we are setting the current gone

62
00:02:28,250 --> 00:02:31,160
to one while we only have one weapon.

63
00:02:31,160 --> 00:02:34,070
So the only index that we can access a 0.

64
00:02:34,070 --> 00:02:37,090
I could set this to 0 if I wanted.

65
00:02:37,085 --> 00:02:39,005
But then what happens

66
00:02:39,005 --> 00:02:41,315
is that every time we start the game,

67
00:02:41,315 --> 00:02:43,465
we have, for example,

68
00:02:43,460 --> 00:02:45,230
the shotgun and the rifle,

69
00:02:45,230 --> 00:02:46,850
and the rifle is on while

70
00:02:46,850 --> 00:02:50,540
the current gun different than you get what I mean.

71
00:02:50,540 --> 00:02:52,000
So the index will be

72
00:02:51,995 --> 00:02:53,905
out of place and this is something that

73
00:02:53,900 --> 00:02:57,470
we didn't take care of in the last video.

74
00:02:57,470 --> 00:03:00,080
So I'll show you what happens even though

75
00:03:00,080 --> 00:03:01,430
this will take a bit of time to

76
00:03:01,430 --> 00:03:02,780
understand, but no worries.

77
00:03:02,780 --> 00:03:05,150
I want to make sure that everything is

78
00:03:05,150 --> 00:03:06,710
properly understood and why

79
00:03:06,710 --> 00:03:08,330
we're doing all of these things.

80
00:03:08,330 --> 00:03:13,420
So pistol, shotgun, rifle, apply the changes.

81
00:03:13,415 --> 00:03:15,565
For example, let's say I turn off

82
00:03:15,560 --> 00:03:21,230
the pistol and I turn off the rifle.

83
00:03:21,230 --> 00:03:24,550
So now what we should have as the shotgun as we begin.

84
00:03:24,545 --> 00:03:26,315
So I'm going to run this.

85
00:03:26,315 --> 00:03:27,085
There we go.

86
00:03:27,080 --> 00:03:29,360
We have the shotgun shooting,

87
00:03:29,360 --> 00:03:31,250
but I have the pistol and the UI.

88
00:03:31,250 --> 00:03:32,410
If I click it again,

89
00:03:32,405 --> 00:03:35,725
then I have the shotgun that I have the rifle.

90
00:03:35,720 --> 00:03:38,870
So as you can see, things are weird at the beginning.

91
00:03:38,870 --> 00:03:40,850
So instead of doing that,

92
00:03:40,850 --> 00:03:42,130
what we're going to do,

93
00:03:42,125 --> 00:03:44,455
we're going to remove this and we

94
00:03:44,450 --> 00:03:47,200
are going to create a for loop.

95
00:03:47,195 --> 00:03:52,495
So four and I equals 0,

96
00:03:52,490 --> 00:04:00,520
I is less than the available weapons dot count,

97
00:04:00,515 --> 00:04:03,925
count because we are using lists and I plus, plus.

98
00:04:03,920 --> 00:04:08,570
And in here I'm going to check if the available weapon,

99
00:04:08,570 --> 00:04:13,660
the position I dot gameObject dot active in hierarchy,

100
00:04:13,655 --> 00:04:15,685
that means which show up and have we actually

101
00:04:15,680 --> 00:04:18,170
chosen to be available to the player?

102
00:04:18,170 --> 00:04:22,450
Then we are going to set the current gun equal to I.

103
00:04:22,445 --> 00:04:25,685
And that way everything should be working perfectly fine.

104
00:04:25,685 --> 00:04:27,505
So if I go back in here,

105
00:04:27,500 --> 00:04:29,260
I have the shotgun.

106
00:04:29,255 --> 00:04:30,895
I run the game.

107
00:04:30,890 --> 00:04:33,590
The weapon should be correct right here.

108
00:04:33,590 --> 00:04:34,670
There we go, shotgun.

109
00:04:34,670 --> 00:04:37,370
Let's test it out on the rifle.

110
00:04:37,369 --> 00:04:39,139
So turn this off, run the game.

111
00:04:39,140 --> 00:04:41,130
So now we should have the rifle.

112
00:04:41,134 --> 00:04:44,514
And there we go, everything is working properly.

113
00:04:44,510 --> 00:04:46,160
And finally, we tested on

114
00:04:46,160 --> 00:04:50,750
the pistol and remove the rifle, run that.

115
00:04:50,750 --> 00:04:52,550
And we should have the pistol.

116
00:04:52,550 --> 00:04:55,310
Okay, great, So everything is working good.

117
00:04:55,310 --> 00:04:58,390
Now, I took a bit of fun to do this.

118
00:04:58,385 --> 00:04:59,905
No worries, but as long as

119
00:04:59,900 --> 00:05:01,820
this is out of the way because it will

120
00:05:01,820 --> 00:05:05,240
be important when we start actually picking up weapons.

121
00:05:05,240 --> 00:05:07,880
So the first thing we need to do is we need to create

122
00:05:07,880 --> 00:05:10,900
the pickup object that we are going to interact with.

123
00:05:10,895 --> 00:05:14,675
And I've created these three sprites right here.

124
00:05:14,675 --> 00:05:16,345
And the difference between

125
00:05:16,340 --> 00:05:19,420
the regular sprites and the guns and

126
00:05:19,415 --> 00:05:21,985
these ones is that I've added a bit of

127
00:05:21,980 --> 00:05:24,740
white layer around the console.

128
00:05:24,740 --> 00:05:26,860
We can see them in the world.

129
00:05:26,855 --> 00:05:29,035
So I'm going to go into the sprites,

130
00:05:29,030 --> 00:05:31,040
right-click in here, create.

131
00:05:31,040 --> 00:05:31,940
Nope.

132
00:05:31,940 --> 00:05:34,910
Create a new folder which is going to

133
00:05:34,910 --> 00:05:40,970
be the weapons backup.

134
00:05:40,970 --> 00:05:43,760
Hit Enter, open this up.

135
00:05:43,760 --> 00:05:45,950
Or we could have added to the pickups,

136
00:05:45,950 --> 00:05:47,390
but no worries about that.

137
00:05:47,390 --> 00:05:49,780
Having more folders never hurt anybody.

138
00:05:49,775 --> 00:05:51,055
So as you can see, there is

139
00:05:51,050 --> 00:05:53,480
a white outline around the shotgun.

140
00:05:53,480 --> 00:05:54,910
So if I add it in here,

141
00:05:54,905 --> 00:05:56,635
set it on the player.

142
00:05:56,630 --> 00:05:59,150
And I'm just going to make all of these

143
00:05:59,150 --> 00:06:02,840
32 and make them point.

144
00:06:02,840 --> 00:06:03,950
Apply the changes.

145
00:06:03,950 --> 00:06:05,330
There we go. So as you can see,

146
00:06:05,330 --> 00:06:07,930
the shotgun has this white outline

147
00:06:07,925 --> 00:06:11,015
around it so we can properly see it and work.

148
00:06:11,015 --> 00:06:13,715
It wasn't that big of a deal whenever we

149
00:06:13,715 --> 00:06:15,355
were holding the weapon

150
00:06:15,350 --> 00:06:17,320
because we have the player as the background.

151
00:06:17,315 --> 00:06:19,895
But now we need to make sure that we can visibly and

152
00:06:19,895 --> 00:06:23,185
easily see the shotgun or any pistol and weapon.

153
00:06:23,180 --> 00:06:25,220
And if you don't like it, honestly,

154
00:06:25,220 --> 00:06:26,960
it took me like, I don't know,

155
00:06:26,960 --> 00:06:28,970
one hour to do this in Photoshop.

156
00:06:28,970 --> 00:06:31,520
I have no clue how good or bad it is.

157
00:06:31,520 --> 00:06:33,430
Maybe some of you are cringing at the work,

158
00:06:33,425 --> 00:06:35,875
but personally, it was my best.

159
00:06:35,870 --> 00:06:37,180
Let's continue one.

160
00:06:37,175 --> 00:06:39,305
So what we're going to do in here

161
00:06:39,305 --> 00:06:42,385
is let's keep this as the shotgun.

162
00:06:42,380 --> 00:06:43,940
We're going to add a component.

163
00:06:43,940 --> 00:06:46,520
Obviously it's going to be the collider.

164
00:06:46,520 --> 00:06:48,610
So a box collider 2D.

165
00:06:48,605 --> 00:06:50,225
Let's see how big that is.

166
00:06:50,225 --> 00:06:51,925
And maybe we can increase

167
00:06:51,920 --> 00:06:55,010
the size a bit on the x and the y.

168
00:06:55,010 --> 00:06:56,900
Don't have to hit

169
00:06:56,900 --> 00:06:59,540
the weapon entirely suits to pick it up.

170
00:06:59,540 --> 00:07:02,660
So just a little bit and have it as a trigger.

171
00:07:02,660 --> 00:07:04,640
We save that. And the next thing we're

172
00:07:04,640 --> 00:07:07,050
going to do obviously is some behavior.

173
00:07:07,054 --> 00:07:09,364
So I'm going to go into the scripts,

174
00:07:09,365 --> 00:07:11,555
go into the pickups,

175
00:07:11,555 --> 00:07:14,635
right-click in here and create a new C-sharp script

176
00:07:14,630 --> 00:07:17,980
which is going to be the weapons backup.

177
00:07:17,975 --> 00:07:20,605
Hit Enter weapons, pick up,

178
00:07:20,600 --> 00:07:24,340
wait for it to compile to the shotgun pickup.

179
00:07:24,335 --> 00:07:25,735
And let's open up the script and

180
00:07:25,730 --> 00:07:27,430
see what we are going to do in here.

181
00:07:27,425 --> 00:07:30,055
Okay, so the first thing that we need,

182
00:07:30,050 --> 00:07:31,610
as we actually need to know

183
00:07:31,610 --> 00:07:33,730
which gun this is going to be.

184
00:07:33,725 --> 00:07:37,195
So the shotgun obviously will give us the shotgun gun.

185
00:07:37,190 --> 00:07:40,090
So I'm going to create a serialized field in here,

186
00:07:40,085 --> 00:07:43,855
which is going to be the weapon system of

187
00:07:43,850 --> 00:07:45,800
type urban system is going to be

188
00:07:45,800 --> 00:07:50,030
the actual weapon that we are going to pick up.

189
00:07:50,030 --> 00:07:51,410
Save that.

190
00:07:51,410 --> 00:07:53,960
Now, the next thing we want to do is we

191
00:07:53,960 --> 00:07:56,770
want to be able to pick this object up.

192
00:07:56,765 --> 00:08:00,995
And before we can actually add this object to the player,

193
00:08:00,995 --> 00:08:02,545
we want to make sure that he

194
00:08:02,540 --> 00:08:04,900
doesn't already have that object.

195
00:08:04,895 --> 00:08:08,155
So I don't want to be carrying around 10 shotguns.

196
00:08:08,150 --> 00:08:12,110
I only need a single shot gun to be available to me.

197
00:08:12,110 --> 00:08:14,590
So let me first of all like this down.

198
00:08:14,585 --> 00:08:16,325
Let's go to the prefab,

199
00:08:16,325 --> 00:08:19,345
go to the weapons,

200
00:08:19,340 --> 00:08:21,890
and let's add the shotgun here as the weapon.

201
00:08:21,890 --> 00:08:24,130
So I hope you understood what I mean.

202
00:08:24,125 --> 00:08:26,245
I don't want to pick up a shotgun

203
00:08:26,240 --> 00:08:28,690
while I already have a shotgun.

204
00:08:28,685 --> 00:08:31,645
I want to pick up a shotgun only if it is

205
00:08:31,640 --> 00:08:34,990
not being held in my available weapons.

206
00:08:34,985 --> 00:08:36,925
And that is your challenge to

207
00:08:36,920 --> 00:08:39,070
look through the layer guns.

208
00:08:39,065 --> 00:08:41,545
So first of all, you need to create an entrepreneur

209
00:08:41,540 --> 00:08:44,050
Enter and check if we collided with a player.

210
00:08:44,045 --> 00:08:45,985
Obviously, we don't want our skeletons to

211
00:08:45,980 --> 00:08:48,230
be attacking us was shot guns.

212
00:08:48,230 --> 00:08:50,320
Who then you'll need to create

213
00:08:50,315 --> 00:08:52,375
a variable inside the method to

214
00:08:52,370 --> 00:08:54,290
keep track of whether we found

215
00:08:54,290 --> 00:08:56,600
the weapon or not on the player.

216
00:08:56,600 --> 00:08:59,230
You need to go through all the guns deep layer

217
00:08:59,225 --> 00:09:03,125
scurrying and obviously check if we're carrying the gun,

218
00:09:03,125 --> 00:09:05,815
you've picked up using the GAN name,

219
00:09:05,810 --> 00:09:08,320
so we'll need the gun name and phone to

220
00:09:08,315 --> 00:09:11,335
access the gun name and to access the available weapons,

221
00:09:11,330 --> 00:09:14,390
you'll need to create a couple of extra methods.

222
00:09:14,390 --> 00:09:16,000
So this is a big challenge,

223
00:09:15,995 --> 00:09:17,435
a very tough challenge,

224
00:09:17,435 --> 00:09:19,375
but I know you're up to the task.

225
00:09:19,370 --> 00:09:21,520
Take your time, play around,

226
00:09:21,515 --> 00:09:23,575
do mistakes, don't worry about it.

227
00:09:23,570 --> 00:09:26,020
I will be there to help you after we've tried.

228
00:09:26,015 --> 00:09:27,695
So you don't lose anything.

229
00:09:27,695 --> 00:09:32,345
Pause the video right now and go do reach Alan.

230
00:09:32,500 --> 00:09:34,760
Kay, welcome back.

231
00:09:34,760 --> 00:09:36,710
So the first thing that I'm going to

232
00:09:36,710 --> 00:09:38,930
do is remove the start and update.

233
00:09:38,930 --> 00:09:41,980
I'm going to create the entrepreneur enter 2D.

234
00:09:41,975 --> 00:09:44,495
And here obviously we check if the

235
00:09:44,495 --> 00:09:48,925
collision.com tag as the player.

236
00:09:48,920 --> 00:09:52,070
And now we can continue on.

237
00:09:52,070 --> 00:09:55,460
Now the next thing and something about here,

238
00:09:55,460 --> 00:09:57,790
maybe we could have just immediately made

239
00:09:57,785 --> 00:10:01,285
all the pickups have a certain layer and make

240
00:10:01,280 --> 00:10:02,330
it only interact with

241
00:10:02,330 --> 00:10:04,690
the player layer that would have been a bit smart

242
00:10:04,685 --> 00:10:06,685
and maybe not have all of

243
00:10:06,680 --> 00:10:08,120
these f conditions every single

244
00:10:08,120 --> 00:10:10,090
time we want to use a pickup.

245
00:10:10,085 --> 00:10:11,875
So just a silent,

246
00:10:11,870 --> 00:10:13,070
I forgot about it.

247
00:10:13,070 --> 00:10:14,960
Maybe you can do it on yourself.

248
00:10:14,960 --> 00:10:17,930
With that said, let's continue on next. What do we want?

249
00:10:17,930 --> 00:10:19,040
Well, obviously we want

250
00:10:19,040 --> 00:10:21,410
this Boolean variable that will say

251
00:10:21,410 --> 00:10:25,910
that gun on player.

252
00:10:25,910 --> 00:10:28,730
And this will be set to false.

253
00:10:28,730 --> 00:10:32,000
Okay, Now the next thing we need to do is we'll need to

254
00:10:32,000 --> 00:10:35,020
create a foreach loop that checks.

255
00:10:35,015 --> 00:10:39,715
And it's going to be checking for guns so or weapons.

256
00:10:39,710 --> 00:10:41,360
So it's the weapon system.

257
00:10:41,360 --> 00:10:45,580
The weapon to check.

258
00:10:45,575 --> 00:10:48,205
And where are we looking for these?

259
00:10:48,200 --> 00:10:49,310
Well, we are looking for

260
00:10:49,310 --> 00:10:52,420
the available guns on the player.

261
00:10:52,415 --> 00:10:54,395
On the player controller,

262
00:10:54,395 --> 00:10:56,215
their goal, it says it right here.

263
00:10:56,210 --> 00:10:59,620
So we are going to look through the available guns,

264
00:10:59,615 --> 00:11:01,675
but obviously available weapons,

265
00:11:01,670 --> 00:11:04,010
but obviously it's a serialized field.

266
00:11:04,010 --> 00:11:05,120
We don't want to make it

267
00:11:05,120 --> 00:11:06,940
public and available to everyone.

268
00:11:06,935 --> 00:11:09,565
So what we'll do is down here,

269
00:11:09,560 --> 00:11:11,500
we're going to Create and

270
00:11:11,495 --> 00:11:13,735
there you can see the mistake that we've made.

271
00:11:13,730 --> 00:11:15,230
We're going to create

272
00:11:15,229 --> 00:11:22,969
a public list of type weapon system.

273
00:11:22,969 --> 00:11:27,189
So I hope you tried this, excuse me.

274
00:11:27,185 --> 00:11:30,545
And we're going to call it the get

275
00:11:30,670 --> 00:11:37,660
available weapons

276
00:11:37,660 --> 00:11:43,690
on layer.

277
00:11:43,690 --> 00:11:46,350
There we go. That's a long name.

278
00:11:46,345 --> 00:11:49,165
And what we're going to do is simply return

279
00:11:49,165 --> 00:11:52,285
the available weapons. There we go.

280
00:11:52,285 --> 00:11:55,155
So now what we can do back in here,

281
00:11:55,150 --> 00:11:56,580
and because we can

282
00:11:56,575 --> 00:11:59,235
immediately access it from the collision,

283
00:11:59,230 --> 00:12:02,200
which we've collided with the Get component.

284
00:12:02,200 --> 00:12:04,590
And because we already know it's the player,

285
00:12:04,585 --> 00:12:07,465
we can access the player controller.

286
00:12:07,465 --> 00:12:09,915
And from the player controller we can get

287
00:12:09,910 --> 00:12:12,550
the available weapons on the player.

288
00:12:12,550 --> 00:12:15,160
Great. So what we've done in here,

289
00:12:15,160 --> 00:12:17,370
we've created the ghetto available weapons

290
00:12:17,370 --> 00:12:19,190
by having the simple return,

291
00:12:19,190 --> 00:12:20,530
which returns a list.

292
00:12:20,525 --> 00:12:22,195
And because it is a list,

293
00:12:22,190 --> 00:12:23,630
we can add it right here.

294
00:12:23,630 --> 00:12:25,990
So we are checking the weapons to check.

295
00:12:25,985 --> 00:12:30,115
Now, how are we going to know if the weapon is there?

296
00:12:30,110 --> 00:12:33,530
What we'll do is we're going to create an if condition.

297
00:12:33,530 --> 00:12:37,460
And in here we are going to check if the weapon that is

298
00:12:37,460 --> 00:12:41,240
in here dot the name of the weapon.

299
00:12:41,240 --> 00:12:44,710
So obviously if I go to the weapons system,

300
00:12:44,705 --> 00:12:46,345
if it's in here somewhere,

301
00:12:46,340 --> 00:12:50,120
the weapons system, we have the weapons name,

302
00:12:50,120 --> 00:12:52,310
but again, it's a serialized field.

303
00:12:52,310 --> 00:12:53,810
So these are okay.

304
00:12:53,810 --> 00:12:57,040
So we do have the get weapons name, UI.

305
00:12:57,035 --> 00:12:58,105
Okay. No worries.

306
00:12:58,100 --> 00:12:59,270
That's all that we need.

307
00:12:59,270 --> 00:13:00,560
Yep, That's all that we need.

308
00:13:00,560 --> 00:13:03,530
So in here we are going to check get

309
00:13:03,530 --> 00:13:09,760
weapons name on the weapons or no,

310
00:13:09,755 --> 00:13:11,815
actually, we don't need this.

311
00:13:11,810 --> 00:13:15,290
Get weapons name you are.

312
00:13:15,290 --> 00:13:19,750
And if it's equal to the weapon to

313
00:13:19,745 --> 00:13:24,635
check dot get weapon name UI.

314
00:13:24,635 --> 00:13:26,335
So maybe UI wasn't

315
00:13:26,330 --> 00:13:29,600
the perfect name in here for the method,

316
00:13:29,600 --> 00:13:31,550
maybe it's better to just call it the name

317
00:13:31,550 --> 00:13:33,790
because we are using it in a different way.

318
00:13:33,785 --> 00:13:35,825
We can double-click create our R

319
00:13:35,825 --> 00:13:38,225
and just use the getWidth and name.

320
00:13:38,225 --> 00:13:39,895
Hit Enter. There we go.

321
00:13:39,890 --> 00:13:41,750
Now we've changed this all over,

322
00:13:41,750 --> 00:13:44,080
even in the weapon system.

323
00:13:44,075 --> 00:13:46,525
Down here, you can see how cool is that.

324
00:13:46,520 --> 00:13:48,610
So Control, double or,

325
00:13:48,605 --> 00:13:50,725
or, or, so if it is there,

326
00:13:50,720 --> 00:13:52,780
that means that the weapon is

327
00:13:52,775 --> 00:13:55,055
already in the available weapons.

328
00:13:55,055 --> 00:13:59,915
So we're going to set the gun on layer to true.

329
00:13:59,915 --> 00:14:01,885
And after we finish looking

330
00:14:01,880 --> 00:14:03,560
through all the available guns,

331
00:14:03,560 --> 00:14:06,100
we are going to after this check-in here,

332
00:14:06,095 --> 00:14:10,975
if V gun on player is not true,

333
00:14:10,970 --> 00:14:13,040
so that means that it's still false.

334
00:14:13,040 --> 00:14:14,740
We don't have the weapon, honest.

335
00:14:14,735 --> 00:14:20,095
What we'll do is we're going to go ahead and instantiate

336
00:14:20,090 --> 00:14:29,810
the weapon on the collision dot get component.

337
00:14:29,810 --> 00:14:33,280
And it's going to be the player controller.

338
00:14:33,275 --> 00:14:35,575
And why am I doing all of these steps?

339
00:14:35,570 --> 00:14:39,400
Well, because I want to actually make this weapon.

340
00:14:39,395 --> 00:14:42,325
If we go back in here, you can see that the weapon is

341
00:14:42,320 --> 00:14:45,860
actually a child of the weapons arm.

342
00:14:45,860 --> 00:14:47,600
So we need to make we

343
00:14:47,600 --> 00:14:49,520
can see right here that an instantiate,

344
00:14:49,520 --> 00:14:51,310
we can set the child.

345
00:14:51,305 --> 00:14:53,575
So we're going to do just that and we

346
00:14:53,570 --> 00:14:56,180
need a reference to the weapons on.

347
00:14:56,180 --> 00:14:58,790
So if I scroll up and here

348
00:14:58,790 --> 00:15:01,630
you can see that we do have a weapons arm.

349
00:15:01,625 --> 00:15:05,125
So all we need to do a scroll down and again,

350
00:15:05,120 --> 00:15:07,610
create a public. And what is it?

351
00:15:07,610 --> 00:15:09,590
It's a transform, I believe.

352
00:15:09,590 --> 00:15:11,410
Yes, say transform.

353
00:15:11,405 --> 00:15:12,755
So we'll need to create

354
00:15:12,755 --> 00:15:21,135
a public transform and get weapons arm.

355
00:15:21,135 --> 00:15:27,475
And we're simply going to return, return the weapons.

356
00:15:27,475 --> 00:15:28,545
Are.

357
00:15:28,540 --> 00:15:32,470
There we go. So that was a hard challenge,

358
00:15:32,470 --> 00:15:35,050
I know, but I hope you at

359
00:15:35,050 --> 00:15:37,630
least try to get halfway through it.

360
00:15:37,630 --> 00:15:39,720
So get weapons.

361
00:15:39,715 --> 00:15:43,995
It's not showing up because it's a public transform.

362
00:15:43,990 --> 00:15:46,060
Get weapons on.

363
00:15:46,060 --> 00:15:51,390
So player controller dot get weapon.

364
00:15:51,385 --> 00:15:53,785
Oh, so player bullet controller.

365
00:15:53,784 --> 00:15:58,704
Okay, So player controller get weapons arm.

366
00:15:58,705 --> 00:16:01,425
And there we go, we save that.

367
00:16:01,420 --> 00:16:04,480
We go back into our game.

368
00:16:04,480 --> 00:16:06,250
And let's see how that works.

369
00:16:06,250 --> 00:16:07,750
So we have the histone and

370
00:16:07,750 --> 00:16:09,480
we have the shotgun on the ground.

371
00:16:09,475 --> 00:16:10,905
We pick up the shotgun,

372
00:16:10,900 --> 00:16:12,220
the weapon available on it,

373
00:16:12,220 --> 00:16:14,070
save that, run the game.

374
00:16:14,065 --> 00:16:17,565
And now when we get close to the shotgun,

375
00:16:17,560 --> 00:16:22,120
nothing happens because if I double-click in here,

376
00:16:22,120 --> 00:16:25,800
we can see that, okay.

377
00:16:25,795 --> 00:16:27,885
And other than that in here,

378
00:16:27,880 --> 00:16:29,220
we get to check.

379
00:16:29,215 --> 00:16:31,215
Okay. So welcome back.

380
00:16:31,210 --> 00:16:34,680
For some reason, I didn't change anything.

381
00:16:34,675 --> 00:16:38,655
I just run the game now and it seems to work.

382
00:16:38,650 --> 00:16:40,360
There we go. You can see that we've picked

383
00:16:40,360 --> 00:16:42,040
up two shotguns. Why is that?

384
00:16:42,040 --> 00:16:43,420
Well, obviously because of

385
00:16:43,420 --> 00:16:45,840
the two colliders that we have on us.

386
00:16:45,835 --> 00:16:48,925
And also don't destroy this shotgun.

387
00:16:48,920 --> 00:16:50,960
But as you can see, we are still

388
00:16:50,960 --> 00:16:53,240
picking the shotgun up multiple times,

389
00:16:53,240 --> 00:16:55,730
even though we can look through this and see

390
00:16:55,730 --> 00:16:58,700
that we have the shotgun already honest now.

391
00:16:58,700 --> 00:17:00,770
So before we continue on,

392
00:17:00,770 --> 00:17:02,510
the first thing that we need to do is

393
00:17:02,510 --> 00:17:04,430
create the private boolean,

394
00:17:04,430 --> 00:17:06,350
just like we have in the health pickup.

395
00:17:06,350 --> 00:17:10,540
So we can just copy this, paste it in here,

396
00:17:10,535 --> 00:17:13,445
and said the pickup to

397
00:17:13,445 --> 00:17:18,265
true whenever we actually pick up the gun.

398
00:17:18,260 --> 00:17:22,250
So in here said this immediately to true.

399
00:17:22,250 --> 00:17:27,470
And we also check if we haven't picked up the weapon yet.

400
00:17:27,470 --> 00:17:29,090
So as you know, this is because we

401
00:17:29,090 --> 00:17:31,120
have the two collider on us.

402
00:17:31,115 --> 00:17:34,105
So save that back in our game.

403
00:17:34,100 --> 00:17:36,380
Let's see how that works.

404
00:17:36,380 --> 00:17:38,030
Now, we run the game.

405
00:17:38,030 --> 00:17:40,130
We have the shotgun. Oh, and we also need

406
00:17:40,130 --> 00:17:42,220
to destroy the weapon, excuse me.

407
00:17:42,215 --> 00:17:44,275
And after we do pick it up,

408
00:17:44,270 --> 00:17:46,460
if we do instantiate the weapon,

409
00:17:46,460 --> 00:17:48,220
where is it for each?

410
00:17:48,215 --> 00:17:50,275
So in here you can choose

411
00:17:50,270 --> 00:17:52,450
whether you want to destroy it in any case.

412
00:17:52,445 --> 00:17:54,595
I believe we should destroy it in any case.

413
00:17:54,590 --> 00:17:57,350
So even if we don't actually pick it up,

414
00:17:57,350 --> 00:17:59,060
it doesn't need to stay there.

415
00:17:59,060 --> 00:18:01,280
So I'm just going to destroy the object as soon

416
00:18:01,280 --> 00:18:03,780
as deep layer actually heads that object.

417
00:18:03,775 --> 00:18:06,875
So back in here, run the game.

418
00:18:06,875 --> 00:18:11,185
And there we go.

419
00:18:11,185 --> 00:18:12,525
We pick up the weapon,

420
00:18:12,520 --> 00:18:14,830
and now we have the shotgun and our hand.

421
00:18:14,830 --> 00:18:17,680
As you can see, the shotgun shoots and we can't

422
00:18:17,680 --> 00:18:19,330
switch the weapons on and out

423
00:18:19,330 --> 00:18:21,190
between the shotgun or the pistol.

424
00:18:21,190 --> 00:18:22,810
Why is that? Well, because we haven't

425
00:18:22,810 --> 00:18:25,120
actually added the shotgun right here

426
00:18:25,120 --> 00:18:27,490
into the available weapons and that is

427
00:18:27,490 --> 00:18:30,280
something that we will need to fix in the next video.

428
00:18:30,280 --> 00:18:31,840
That is also the reason

429
00:18:31,840 --> 00:18:33,880
why we saw right here that we have

430
00:18:33,880 --> 00:18:36,760
multiple shotguns being picked

431
00:18:36,760 --> 00:18:38,800
up without the weapon being destroyed.

432
00:18:38,800 --> 00:18:42,460
That will be fixed in the next video where we actually

433
00:18:42,460 --> 00:18:44,350
start adding the picked up weapon

434
00:18:44,350 --> 00:18:46,480
into the available weapons.

435
00:18:46,480 --> 00:18:48,340
So that said, I hope you enjoy it.

436
00:18:48,340 --> 00:18:50,080
Make sure to commit

437
00:18:50,080 --> 00:18:53,630
your changes and I'll see you in the next one.

