1
00:00:00,000 --> 00:00:03,750
Welcome back my fellow game developers

2
00:00:03,750 --> 00:00:05,610
to a brand new video,

3
00:00:05,610 --> 00:00:07,470
a brand new long video.

4
00:00:07,470 --> 00:00:11,340
But it is worth it because now when we run the game,

5
00:00:11,340 --> 00:00:13,070
we pick up some coins.

6
00:00:13,065 --> 00:00:16,115
We go here, okay, So we can restore health,

7
00:00:16,110 --> 00:00:19,380
we can upgrade health or we can do something much cooler,

8
00:00:19,380 --> 00:00:22,290
and that is by ourselves some weapon.

9
00:00:22,290 --> 00:00:24,270
So we get a rifle and then we

10
00:00:24,270 --> 00:00:26,260
can go and shoot it everywhere.

11
00:00:26,264 --> 00:00:28,204
So let's not waste

12
00:00:28,200 --> 00:00:31,550
any more time and let's get to buying weapons,

13
00:00:31,545 --> 00:00:35,225
visas like Paxos, any case.

14
00:00:35,220 --> 00:00:39,150
So time for the last item that we can buy,

15
00:00:39,150 --> 00:00:41,080
which is the weapon.

16
00:00:41,080 --> 00:00:44,050
So I'm going to go into the item sprite.

17
00:00:44,045 --> 00:00:47,995
And by the way, what I did offscreen is that I

18
00:00:47,990 --> 00:00:50,330
added a couple of animations and make

19
00:00:50,330 --> 00:00:52,700
sure that the item sprite is on a different level.

20
00:00:52,700 --> 00:00:55,400
So there you can see all of them rotate and

21
00:00:55,400 --> 00:00:56,690
you can see the platform have

22
00:00:56,690 --> 00:00:58,390
this little animation on it.

23
00:00:58,385 --> 00:00:59,975
Pretty simple, pretty easy.

24
00:00:59,975 --> 00:01:02,165
I'm not going to go too deep into that.

25
00:01:02,165 --> 00:01:04,795
But what I am going to do is I'm going to

26
00:01:04,790 --> 00:01:07,810
go in here and change these pride on the last one.

27
00:01:07,805 --> 00:01:10,985
And let's go into the sprites.

28
00:01:10,985 --> 00:01:12,425
Pickups.

29
00:01:12,425 --> 00:01:13,855
Nope, not pickups.

30
00:01:13,850 --> 00:01:15,290
Weapons weapon,

31
00:01:15,290 --> 00:01:17,980
weapon weapon weapon pickup.

32
00:01:17,975 --> 00:01:22,385
Select this one and let's just add the rifle for now.

33
00:01:22,385 --> 00:01:23,375
There we go.

34
00:01:23,375 --> 00:01:24,175
Can see it.

35
00:01:24,170 --> 00:01:25,690
Let's make it a bit bigger.

36
00:01:25,685 --> 00:01:26,665
Sorry for that.

37
00:01:26,660 --> 00:01:30,620
We should somehow keep the aspect ratio.

38
00:01:30,619 --> 00:01:31,399
Now what?

39
00:01:31,400 --> 00:01:33,350
Let's just increase the scale by two,

40
00:01:33,350 --> 00:01:37,820
by two, by 1.5, by 1.5.

41
00:01:37,820 --> 00:01:39,880
Okay, great. So now when we run the game,

42
00:01:39,875 --> 00:01:41,275
I believe this should be

43
00:01:41,270 --> 00:01:44,450
spinning because it has the animator. There we go.

44
00:01:44,450 --> 00:01:46,390
You can see that it's spins

45
00:01:46,385 --> 00:01:49,235
around and wait for us to come and collected.

46
00:01:49,235 --> 00:01:51,205
Now, the difference between

47
00:01:51,200 --> 00:01:52,970
the two other items and

48
00:01:52,970 --> 00:01:55,400
the weapon item is that we don't want to have,

49
00:01:55,400 --> 00:01:57,670
for example, just an item 40 rifle.

50
00:01:57,665 --> 00:02:00,355
We want to get some kind of random item or

51
00:02:00,350 --> 00:02:03,550
random weapon when we want to buy a weapon.

52
00:02:03,545 --> 00:02:05,215
So I'm going to go into

53
00:02:05,210 --> 00:02:08,750
the item script and this error is bothering me a lot.

54
00:02:08,750 --> 00:02:12,110
And in the shop item in here,

55
00:02:12,110 --> 00:02:15,490
I'm going to create a couple of lines.

56
00:02:15,485 --> 00:02:17,065
So first thing first,

57
00:02:17,060 --> 00:02:19,570
I want to create a serialized field

58
00:02:19,565 --> 00:02:22,715
of the weapons system.

59
00:02:22,715 --> 00:02:25,105
And it's going to be an array of

60
00:02:25,100 --> 00:02:29,990
the potential weapons to buy.

61
00:02:29,990 --> 00:02:32,270
That is a long name for a variable.

62
00:02:32,270 --> 00:02:36,830
And then I'm going to create a private and the weapon

63
00:02:36,830 --> 00:02:43,510
system and the actual weapon, no weapon too.

64
00:02:43,505 --> 00:02:45,815
By, There we go.

65
00:02:45,815 --> 00:02:48,215
And finally, we are going to do two things.

66
00:02:48,215 --> 00:02:49,615
The first thing is going to

67
00:02:49,610 --> 00:02:51,530
get this right because we want

68
00:02:51,530 --> 00:02:53,090
to change the sprite based on

69
00:02:53,090 --> 00:02:54,950
the weapon that we are going to buy.

70
00:02:54,950 --> 00:02:59,740
So private sprite, renderer.

71
00:02:59,735 --> 00:03:03,605
And there we go. And the item sprite,

72
00:03:03,605 --> 00:03:06,685
not the item sprite, the weapon sprite.

73
00:03:06,680 --> 00:03:08,330
So weapon,

74
00:03:08,330 --> 00:03:11,320
so because this is only going to be used for the weapon.

75
00:03:11,315 --> 00:03:14,945
And then we are going to get the serialized field,

76
00:03:14,945 --> 00:03:20,015
the text Mesh Pro or TMP Pro,

77
00:03:20,015 --> 00:03:22,525
Tempe pro, yeah, shorthand P Pro.

78
00:03:22,520 --> 00:03:23,750
And this is going to be

79
00:03:23,750 --> 00:03:29,390
the price text we want to change the price based on,

80
00:03:29,390 --> 00:03:32,000
okay, So we can't use this because we

81
00:03:32,000 --> 00:03:35,410
need TMP Pro, sorry for that.

82
00:03:35,405 --> 00:03:37,465
Or you know what we can do actually, we can,

83
00:03:37,460 --> 00:03:41,650
instead of using TMP probe dot text Mesh pro Gu.

84
00:03:41,645 --> 00:03:42,815
There we go.

85
00:03:42,815 --> 00:03:45,515
So that way we don't need to add an entire library.

86
00:03:45,515 --> 00:03:49,165
So this is just a novel way of doing things.

87
00:03:49,160 --> 00:03:52,370
And now that we have a price for each of

88
00:03:52,370 --> 00:03:55,400
our weapons and a sprite for each of our weapons.

89
00:03:55,400 --> 00:03:58,120
Let's go into the weapons system.

90
00:03:58,115 --> 00:04:00,785
And let's go ahead in here and create

91
00:04:00,785 --> 00:04:04,255
a serialized field for the price of the weapons.

92
00:04:04,250 --> 00:04:07,630
So int weapon price.

93
00:04:07,625 --> 00:04:12,745
And we'll also create a serialized field for the sprite.

94
00:04:12,740 --> 00:04:18,000
And this will be the weapon shop sprite.

95
00:04:18,160 --> 00:04:21,650
And obviously all of these are serialized fields,

96
00:04:21,650 --> 00:04:23,060
so we cannot access them.

97
00:04:23,060 --> 00:04:25,670
So we need to create a couple of methods in here.

98
00:04:25,670 --> 00:04:32,230
The first one will be a public and what and,

99
00:04:32,225 --> 00:04:36,605
and get a weapon price.

100
00:04:36,605 --> 00:04:42,755
And this will return the weapon price.

101
00:04:42,755 --> 00:04:49,675
And then we will have a public sprite for right,

102
00:04:49,670 --> 00:04:57,350
and get a weapon shop sprite.

103
00:04:57,350 --> 00:05:00,290
And this will return,

104
00:05:00,290 --> 00:05:05,740
return the weapon, right?

105
00:05:05,735 --> 00:05:07,615
Weapon shop sprite. There we go.

106
00:05:07,610 --> 00:05:09,500
So the weapon image and the weapons

107
00:05:09,500 --> 00:05:11,810
Sprite are totally different things.

108
00:05:11,810 --> 00:05:13,490
Maybe they shouldn't be,

109
00:05:13,490 --> 00:05:14,720
maybe we can have just

110
00:05:14,720 --> 00:05:16,580
one that returns the entire sprite.

111
00:05:16,580 --> 00:05:17,900
But if you look in here,

112
00:05:17,900 --> 00:05:19,190
I want to have the one with

113
00:05:19,190 --> 00:05:21,880
the white little white thin line

114
00:05:21,875 --> 00:05:25,585
around it so we can easily distinguish the weapon.

115
00:05:25,580 --> 00:05:29,410
In what you can even change this right here, this one.

116
00:05:29,405 --> 00:05:31,135
Let's not worry about that.

117
00:05:31,130 --> 00:05:33,310
Let's keep going the way we are.

118
00:05:33,305 --> 00:05:36,025
Those little small tricks can then at

119
00:05:36,020 --> 00:05:38,380
the end be adjusted and we can change all of this.

120
00:05:38,375 --> 00:05:41,605
So now let's go into the weapons.

121
00:05:41,600 --> 00:05:47,380
Were are the weapons they are in the prefabs.

122
00:05:47,375 --> 00:05:50,585
The residual, residual reserved,

123
00:05:50,585 --> 00:05:54,165
the broken enemy weapons.

124
00:05:54,169 --> 00:05:54,709
There we go.

125
00:05:54,710 --> 00:05:57,350
So the rifle that

126
00:05:57,350 --> 00:05:59,600
slot this down and let's see what we have in here.

127
00:05:59,600 --> 00:06:02,300
So the weapon shop sprite and the weapon price,

128
00:06:02,300 --> 00:06:04,120
how much does the rifle cost?

129
00:06:04,115 --> 00:06:08,075
Let's say 10. Let's say the pistol costs 20.

130
00:06:08,074 --> 00:06:09,684
Nope, sorry for that.

131
00:06:09,680 --> 00:06:10,220
Now what?

132
00:06:10,220 --> 00:06:13,650
Let's make the rifle costs 20.

133
00:06:14,290 --> 00:06:19,120
Let's go back. The pistol will cost ten,

134
00:06:19,115 --> 00:06:21,625
and the shotgun will cost 30.

135
00:06:21,620 --> 00:06:23,470
And these are just arbitrary numbers.

136
00:06:23,465 --> 00:06:25,745
I don't know whatever you want to use US.

137
00:06:25,745 --> 00:06:26,395
Law.

138
00:06:26,390 --> 00:06:28,940
Let's go set up the sprites.

139
00:06:28,940 --> 00:06:31,600
So I'm going to make this one a bit bigger

140
00:06:31,595 --> 00:06:34,535
so I can see the names in here faster.

141
00:06:34,535 --> 00:06:36,985
And what do we have in here?

142
00:06:36,980 --> 00:06:37,700
Pickups?

143
00:06:37,700 --> 00:06:40,180
Nope. Every single time. Okay.

144
00:06:40,175 --> 00:06:46,495
So add the shotgun sprite for the rifle.

145
00:06:47,650 --> 00:06:51,050
Unlock this for the rifle.

146
00:06:51,050 --> 00:06:54,390
I'm going to no, no, no, no.

147
00:06:57,640 --> 00:07:01,060
This is a bit cumbersome, isn't it?

148
00:07:01,055 --> 00:07:05,135
So anywhere at the rifle.

149
00:07:05,135 --> 00:07:07,945
And finally, we select

150
00:07:07,940 --> 00:07:11,050
the weapons and the Prefab, the pistol.

151
00:07:11,045 --> 00:07:14,935
Weapons, pick up the PESTEL, we save that.

152
00:07:14,930 --> 00:07:18,220
And now we have a reference to all of these. Great.

153
00:07:18,215 --> 00:07:20,105
Now that we have the sprite,

154
00:07:20,105 --> 00:07:21,805
we have the weapon price,

155
00:07:21,800 --> 00:07:24,800
the next thing to do is to go and start and set

156
00:07:24,800 --> 00:07:28,240
everything up as soon as the weapons thoughts.

157
00:07:28,235 --> 00:07:31,255
So in the shop item in here, I'm going to save,

158
00:07:31,250 --> 00:07:34,870
I'm going to create a start,

159
00:07:34,865 --> 00:07:37,455
and I'm going to issue you a challenge.

160
00:07:37,459 --> 00:07:39,349
So your challenge is to check type,

161
00:07:39,350 --> 00:07:42,130
select random weapons, set the sprite, and the tax.

162
00:07:42,125 --> 00:07:47,035
So and start check if we have a weapon type item,

163
00:07:47,030 --> 00:07:49,210
you'll need to select a random gun

164
00:07:49,205 --> 00:07:51,425
from potential guns or potential weapons.

165
00:07:51,425 --> 00:07:55,795
And you'll need to set the item cost as the weapon price.

166
00:07:55,790 --> 00:07:59,030
You'll need to set the sprite as the appropriate gun.

167
00:07:59,030 --> 00:08:01,640
You'll need to satisfy texts also.

168
00:08:01,640 --> 00:08:04,310
And I believe this is the last point.

169
00:08:04,310 --> 00:08:06,260
So with that out of the way,

170
00:08:06,260 --> 00:08:11,690
pause the video right now and go to the HL7.

171
00:08:11,690 --> 00:08:13,910
Oh, okay, welcome back.

172
00:08:13,910 --> 00:08:17,870
So in start, That's that's not what I meant.

173
00:08:17,870 --> 00:08:21,440
If we have an item type that is equal

174
00:08:21,440 --> 00:08:25,570
to the item type weapon.

175
00:08:25,565 --> 00:08:28,705
Then in here we are going to set a couple of things.

176
00:08:28,700 --> 00:08:30,010
First of all, we'll create

177
00:08:30,005 --> 00:08:34,285
a random selected weapon

178
00:08:34,280 --> 00:08:39,280
and it's going to be equal to random dot range.

179
00:08:39,275 --> 00:08:43,295
The 0 and the potential.

180
00:08:43,295 --> 00:08:44,785
What is this?

181
00:08:44,780 --> 00:08:49,090
The potential weapons to buy dot length.

182
00:08:49,085 --> 00:08:51,955
Then in here we are going to select

183
00:08:51,950 --> 00:08:54,460
the weapon to buy and it's going to be

184
00:08:54,455 --> 00:08:56,725
equal to the potential weapon to

185
00:08:56,720 --> 00:09:01,070
buy on the position of the selected weapon.

186
00:09:01,070 --> 00:09:04,610
Then we are going to go ahead and get the item cost,

187
00:09:04,610 --> 00:09:06,800
which is going to be the weapon to buy,

188
00:09:06,800 --> 00:09:09,760
that get weapon price.

189
00:09:09,755 --> 00:09:12,115
There we go. And finally,

190
00:09:12,110 --> 00:09:13,790
we are going to set this pride.

191
00:09:13,790 --> 00:09:16,400
So how are we going to first of all get the sprite?

192
00:09:16,400 --> 00:09:21,160
We are going to get component and children the sprite.

193
00:09:21,155 --> 00:09:26,425
Or know what maybe this one in here we won't be needing.

194
00:09:26,420 --> 00:09:28,100
But anyways, let's just skip it.

195
00:09:28,100 --> 00:09:32,020
We'll go into the sprite renderer.

196
00:09:32,015 --> 00:09:33,475
This is the component on

197
00:09:33,470 --> 00:09:34,880
the children, why the children while?

198
00:09:34,880 --> 00:09:38,290
Because on this item which has the actual script,

199
00:09:38,285 --> 00:09:40,075
the item sprite is down here.

200
00:09:40,070 --> 00:09:42,580
And because no other game objects, oh,

201
00:09:42,575 --> 00:09:44,185
we do have another game object

202
00:09:44,180 --> 00:09:46,270
which is the item platform.

203
00:09:46,265 --> 00:09:48,055
This will be a tricky one.

204
00:09:48,050 --> 00:09:49,850
So, you know what,

205
00:09:49,850 --> 00:09:54,260
for the sake of having everything properly set up,

206
00:09:54,260 --> 00:10:00,170
I'm going to make this a serialized field and save that.

207
00:10:00,170 --> 00:10:02,530
And then go back, sorry.

208
00:10:02,525 --> 00:10:05,995
And then go back and to every single one of those

209
00:10:05,990 --> 00:10:10,200
and wait a second.

210
00:10:13,380 --> 00:10:16,720
Weapons sprite renderer.

211
00:10:16,720 --> 00:10:20,350
I was and I was confused.

212
00:10:20,350 --> 00:10:23,500
I was confused there for a second,

213
00:10:23,500 --> 00:10:25,440
sorry for that back in here.

214
00:10:25,435 --> 00:10:33,055
So I'm going to go ahead and add the item sprite.

215
00:10:33,055 --> 00:10:39,085
And here the sprite.

216
00:10:39,085 --> 00:10:42,285
And in here also the item sprite.

217
00:10:42,280 --> 00:10:44,290
So we don't confuse any of these.

218
00:10:44,290 --> 00:10:46,240
And also, as long as we're here,

219
00:10:46,240 --> 00:10:52,040
let's go ahead and add also the price text. So.

220
00:10:56,230 --> 00:10:58,760
Okay, so for some reason I

221
00:10:58,760 --> 00:11:00,710
forgot to change the name of these.

222
00:11:00,710 --> 00:11:06,760
So this will be the item price text

223
00:11:06,755 --> 00:11:09,235
for some reason I thought we did change the student.

224
00:11:09,230 --> 00:11:12,290
Be no worries about that.

225
00:11:12,290 --> 00:11:18,650
And these are the things that we have to do.

226
00:11:18,650 --> 00:11:19,760
We don't like them,

227
00:11:19,760 --> 00:11:22,630
but we have to do them at some point in time.

228
00:11:22,625 --> 00:11:27,785
So let's go ahead and set everything up.

229
00:11:27,785 --> 00:11:29,875
There we go. So now we have a reference to

230
00:11:29,870 --> 00:11:32,270
all of these. Back in here.

231
00:11:32,270 --> 00:11:35,450
The weapons sprite renderer.

232
00:11:35,450 --> 00:11:38,800
The sprite is going to be

233
00:11:38,795 --> 00:11:42,815
equal to the weapon to buy that,

234
00:11:42,815 --> 00:11:46,745
get weapons shop sprite.

235
00:11:46,745 --> 00:11:47,735
There we go.

236
00:11:47,735 --> 00:11:48,875
Save that.

237
00:11:48,875 --> 00:11:50,845
And the last thing that we need to

238
00:11:50,840 --> 00:11:52,970
do is we need to set the text.

239
00:11:52,970 --> 00:11:55,690
So we're going to get the price text.

240
00:11:55,685 --> 00:11:59,825
The text. And what do we say in here?

241
00:11:59,825 --> 00:12:05,585
Let's see what was originally written in here by weapon.

242
00:12:05,585 --> 00:12:07,315
So instead of just by weapon,

243
00:12:07,310 --> 00:12:10,090
we'll start off with by.

244
00:12:10,085 --> 00:12:13,795
Then we are going to concatenate it with the weapon

245
00:12:13,790 --> 00:12:16,870
to buy dot get weapon name.

246
00:12:16,865 --> 00:12:18,025
And this is a string,

247
00:12:18,020 --> 00:12:19,760
so we can do this legally.

248
00:12:19,760 --> 00:12:22,580
And then we will say the price.

249
00:12:22,580 --> 00:12:28,690
So we'll add these two plus the item cost, item cost.

250
00:12:28,685 --> 00:12:30,505
And this is an integer.

251
00:12:30,500 --> 00:12:32,820
So remember when we had an integer

252
00:12:32,824 --> 00:12:35,604
previously in somewhere, I forgot.

253
00:12:35,600 --> 00:12:38,120
So you remember because it was an integer,

254
00:12:38,120 --> 00:12:39,350
we couldn't just sell it.

255
00:12:39,350 --> 00:12:41,620
We had to say dot toString.

256
00:12:41,615 --> 00:12:45,025
So and maybe I wasn't clear what this does.

257
00:12:45,020 --> 00:12:47,230
So toString just converts

258
00:12:47,225 --> 00:12:49,165
any integer or any float

259
00:12:49,160 --> 00:12:50,960
into a string and you can use it.

260
00:12:50,960 --> 00:12:53,930
But in here, because we are concatenating,

261
00:12:53,930 --> 00:12:56,440
concatenating means we add a plus

262
00:12:56,435 --> 00:13:00,355
between a string and an integer or a string and a float.

263
00:13:00,350 --> 00:13:04,310
So when we concatenate a string with an item or sorry,

264
00:13:04,310 --> 00:13:06,530
with an integer, then we don't need

265
00:13:06,530 --> 00:13:08,870
to add two string immediately.

266
00:13:08,870 --> 00:13:12,220
Visual Studio and C Sharp code understands that this,

267
00:13:12,215 --> 00:13:14,155
although it's an integer in here,

268
00:13:14,150 --> 00:13:15,980
we are using it as a string.

269
00:13:15,980 --> 00:13:21,680
So we save that and we also need to add in here BTC.

270
00:13:21,680 --> 00:13:23,200
Save that.

271
00:13:23,195 --> 00:13:25,015
And now let's go back into

272
00:13:25,010 --> 00:13:26,870
our game and see if this works.

273
00:13:26,870 --> 00:13:28,430
We still haven't added the gun,

274
00:13:28,430 --> 00:13:30,140
but let's see if this actually

275
00:13:30,140 --> 00:13:32,240
works are random selection.

276
00:13:32,240 --> 00:13:33,670
So let's go down here.

277
00:13:33,665 --> 00:13:35,085
Okay, so a rifle.

278
00:13:35,089 --> 00:13:36,709
There we go buy a weapon and it

279
00:13:36,710 --> 00:13:38,480
did not work. Why is that?

280
00:13:38,480 --> 00:13:41,210
Because we haven't added anything to the array.

281
00:13:41,210 --> 00:13:44,450
So in here, we need to add the potential weapons to buy.

282
00:13:44,450 --> 00:13:46,580
And it's a consistent so up here in

283
00:13:46,580 --> 00:13:50,260
the prefabs, prefabs weapons,

284
00:13:50,255 --> 00:13:51,895
select the potential weapons

285
00:13:51,890 --> 00:13:53,720
and let's just have the shotgun and

286
00:13:53,720 --> 00:13:57,290
the rifle because we are holding a pistol and our hand.

287
00:13:57,290 --> 00:13:58,730
So run the game.

288
00:13:58,730 --> 00:14:00,650
Let's go and see what happens.

289
00:14:00,650 --> 00:14:01,940
So a rifle there we go.

290
00:14:01,940 --> 00:14:04,000
Buy a rifle for 20 bitcoins.

291
00:14:03,995 --> 00:14:06,025
Let's try this again to try

292
00:14:06,020 --> 00:14:08,060
to get the shotgun, make sure it works.

293
00:14:08,060 --> 00:14:11,420
There we go. The shotgun by the shotgun, 430 bit coins.

294
00:14:11,420 --> 00:14:12,800
But now when we press E,

295
00:14:12,800 --> 00:14:14,840
nothing happens because we still

296
00:14:14,840 --> 00:14:17,500
haven't added any way of buying.

297
00:14:17,495 --> 00:14:19,205
So back down here,

298
00:14:19,205 --> 00:14:21,505
we're going to create a case.

299
00:14:21,500 --> 00:14:29,270
And this case will be for the item type dot the weapon.

300
00:14:29,270 --> 00:14:31,480
There we go. And now

301
00:14:31,475 --> 00:14:33,545
in here we are going to first of all,

302
00:14:33,545 --> 00:14:37,955
find the player that we want to add, the weapons too.

303
00:14:37,955 --> 00:14:40,405
So in here I'm going to say that we

304
00:14:40,400 --> 00:14:43,360
have a player controller,

305
00:14:43,355 --> 00:14:47,065
which is the player Who's buying

306
00:14:47,060 --> 00:14:50,960
the player, the player buying.

307
00:14:50,960 --> 00:14:53,110
So player buying.

308
00:14:53,105 --> 00:14:55,835
I really have a hard time

309
00:14:55,835 --> 00:14:58,165
with selecting names for

310
00:14:58,160 --> 00:15:00,530
objects of finite object of type.

311
00:15:00,530 --> 00:15:01,730
And as you can see, we have

312
00:15:01,730 --> 00:15:04,070
redundant code every single time.

313
00:15:04,070 --> 00:15:05,720
Maybe we should change this.

314
00:15:05,720 --> 00:15:08,230
We are doing a lot of finding.

315
00:15:08,225 --> 00:15:10,255
I don't know, I think we

316
00:15:10,250 --> 00:15:11,990
should change this at some point.

317
00:15:11,990 --> 00:15:14,030
So instead of declare health handler,

318
00:15:14,030 --> 00:15:16,700
we are going to get the player controller.

319
00:15:16,700 --> 00:15:18,400
There we go. So now we have

320
00:15:18,395 --> 00:15:20,275
a reference to the player controller.

321
00:15:20,270 --> 00:15:22,220
Then in here we are going to say

322
00:15:22,220 --> 00:15:24,710
that the gun that we have,

323
00:15:24,710 --> 00:15:31,220
so we're going to instantiate the weapon that we have.

324
00:15:31,220 --> 00:15:33,830
So the weapon to buy.

325
00:15:33,830 --> 00:15:37,930
And we're going to instantiate on the player buying dot.

326
00:15:37,925 --> 00:15:39,595
Get weapons are.

327
00:15:39,590 --> 00:15:45,550
So just like we did when we were picking up a weapon.

328
00:15:45,545 --> 00:15:48,025
So we instantiate the weapon on the guns arm.

329
00:15:48,020 --> 00:15:49,760
And the last thing that we need to do,

330
00:15:49,760 --> 00:15:51,710
we need to also said that weapon

331
00:15:51,710 --> 00:15:54,340
on the players available gun.

332
00:15:54,335 --> 00:15:58,745
So we are going to go ahead and get a reference to this.

333
00:15:58,745 --> 00:16:00,385
Because if I remember correctly,

334
00:16:00,380 --> 00:16:01,670
if we are buying

335
00:16:01,670 --> 00:16:04,490
gun dot add weapon available, there you go.

336
00:16:04,490 --> 00:16:06,950
You can see that takes in the weapon to add.

337
00:16:06,950 --> 00:16:09,230
So we need to get a reference in here,

338
00:16:09,230 --> 00:16:11,420
or you can actually copy this and put it in here.

339
00:16:11,420 --> 00:16:12,830
That doesn't look very pretty,

340
00:16:12,830 --> 00:16:14,630
that doesn't look very professional.

341
00:16:14,630 --> 00:16:15,860
If you look back at the code,

342
00:16:15,860 --> 00:16:18,470
you won't understand exactly what's happening.

343
00:16:18,470 --> 00:16:19,910
So instead, we're going to

344
00:16:19,910 --> 00:16:22,510
create a weapon system in here.

345
00:16:22,505 --> 00:16:29,345
And it's the weapon to add an equal to instantiate.

346
00:16:29,345 --> 00:16:31,645
And then in here we said the weapon to

347
00:16:31,640 --> 00:16:34,360
add and do not forget to break.

348
00:16:34,355 --> 00:16:37,105
This is something that we need and

349
00:16:37,100 --> 00:16:40,250
just in case we are going to create the default in here.

350
00:16:40,250 --> 00:16:45,200
This says that if none of these work then default debug,

351
00:16:45,200 --> 00:16:54,650
thought log, and no item type was chosen.

352
00:16:54,650 --> 00:16:55,090
And all.

353
00:16:55,085 --> 00:16:58,235
I really like the switch cases. They are really nice.

354
00:16:58,235 --> 00:17:01,435
If you look at them. They really look very nice.

355
00:17:01,430 --> 00:17:02,600
So you have a case,

356
00:17:02,600 --> 00:17:05,420
everything is really properly arranged.

357
00:17:05,420 --> 00:17:07,900
So let's go back and see what happens in here.

358
00:17:07,895 --> 00:17:09,325
In case it's a weapon,

359
00:17:09,320 --> 00:17:11,410
we get the player controller,

360
00:17:11,405 --> 00:17:13,015
a reference to the player controller.

361
00:17:13,010 --> 00:17:15,370
We only have one, so this is no problem.

362
00:17:15,365 --> 00:17:17,815
We then instantiate the weapon.

363
00:17:17,810 --> 00:17:19,340
We set it in a variable,

364
00:17:19,339 --> 00:17:22,089
and of course we set it on the player buying,

365
00:17:22,085 --> 00:17:24,845
which has an army always want to set the child,

366
00:17:24,845 --> 00:17:26,575
we set the parent of

367
00:17:26,570 --> 00:17:29,090
the weapon that we've instantiated as the arm,

368
00:17:29,090 --> 00:17:30,940
and then we get the player buying,

369
00:17:30,935 --> 00:17:32,195
we add the available weapon.

370
00:17:32,195 --> 00:17:33,775
Obviously we need to have,

371
00:17:33,770 --> 00:17:35,290
as you remember in here,

372
00:17:35,285 --> 00:17:37,625
we have the available weapons on the player.

373
00:17:37,625 --> 00:17:38,885
We add that weapon,

374
00:17:38,885 --> 00:17:41,115
we break and we have our Robins.

375
00:17:41,110 --> 00:17:42,770
So back in again.

376
00:17:42,770 --> 00:17:44,860
Let's see if that works.

377
00:17:44,855 --> 00:17:46,405
Run the game.

378
00:17:46,400 --> 00:17:50,420
And we pick up some coins to buy ourselves a shotgun.

379
00:17:50,420 --> 00:17:52,750
So now we have a pistol, we get the shotgun.

380
00:17:52,745 --> 00:17:53,875
How cool is that?

381
00:17:53,870 --> 00:17:55,600
So now we have a shotgun,

382
00:17:55,595 --> 00:17:58,235
and not only do we have in here,

383
00:17:58,235 --> 00:18:01,015
I wish I did not use the maximize on

384
00:18:01,010 --> 00:18:04,690
play and maximize, Let's just remove it.

385
00:18:04,685 --> 00:18:06,805
So not only do we have the shotgun and

386
00:18:06,800 --> 00:18:09,200
arms and it works and it shoots and it does everything.

387
00:18:09,200 --> 00:18:12,470
But we also, if we go, Where is it?

388
00:18:12,470 --> 00:18:17,650
Where is it on the DOM player? Unlock this one here.

389
00:18:17,645 --> 00:18:18,175
There you go.

390
00:18:18,170 --> 00:18:21,020
You can see that we have a shotgun and a pistol.

391
00:18:21,020 --> 00:18:22,850
So with that out of the way,

392
00:18:22,850 --> 00:18:26,090
we've finished creating all of our shopping items.

393
00:18:26,090 --> 00:18:27,290
I hope you enjoy it.

394
00:18:27,290 --> 00:18:30,730
I hope you like how the game is turning out to be.

395
00:18:30,725 --> 00:18:34,375
Make sure to always commit your changes

396
00:18:34,370 --> 00:18:36,380
and make sure to leave me a review if

397
00:18:36,380 --> 00:18:38,320
you haven't already with that said,

398
00:18:38,315 --> 00:18:42,215
I'll see you in the next video.

