1
00:00:00,000 --> 00:00:03,780
Hey, welcome back, my fellow game developers.

2
00:00:03,780 --> 00:00:06,990
In this video, we haven't changed much,

3
00:00:06,990 --> 00:00:09,030
but what we did is we just

4
00:00:09,030 --> 00:00:12,110
started setting up a proper weapons system.

5
00:00:12,105 --> 00:00:15,725
We moved the shooting mechanic

6
00:00:15,720 --> 00:00:18,960
from the doom player to the actual weapon,

7
00:00:18,960 --> 00:00:20,070
which is the Sharp console.

8
00:00:20,070 --> 00:00:22,200
As you can see, there is nothing new in here.

9
00:00:22,200 --> 00:00:24,360
We just did a couple of changes.

10
00:00:24,360 --> 00:00:26,400
This video is all about,

11
00:00:26,400 --> 00:00:28,050
let's call it upgrading

12
00:00:28,050 --> 00:00:30,690
your project so you get to a certain point.

13
00:00:30,685 --> 00:00:33,745
You have all the basic mechanics that you want,

14
00:00:33,740 --> 00:00:36,980
but now it's time to make them much more efficient.

15
00:00:36,980 --> 00:00:38,870
So without any further ado,

16
00:00:38,870 --> 00:00:40,430
let's not waste any more time.

17
00:00:40,430 --> 00:00:43,750
And let's make the project grade again.

18
00:00:43,745 --> 00:00:45,565
0 case.

19
00:00:45,560 --> 00:00:48,580
So it's time to create a more

20
00:00:48,575 --> 00:00:52,355
advanced and the professional shooting system.

21
00:00:52,355 --> 00:00:54,475
So the first thing that we are going

22
00:00:54,470 --> 00:00:56,650
to do is we are going to move

23
00:00:56,645 --> 00:00:58,945
everything that is related to

24
00:00:58,940 --> 00:01:01,450
shooting from the player controller

25
00:01:01,445 --> 00:01:04,555
into a separate script

26
00:01:04,550 --> 00:01:06,610
that I'm going to create right now.

27
00:01:06,605 --> 00:01:08,855
If I go into the scripts

28
00:01:08,854 --> 00:01:12,814
and maybe let's make this a little bit bigger.

29
00:01:12,815 --> 00:01:16,345
So we can see them at least and two rows.

30
00:01:16,340 --> 00:01:18,880
These, okay, there we go.

31
00:01:18,875 --> 00:01:21,905
I'm going to go in right here.

32
00:01:21,905 --> 00:01:24,415
I'm creating a folder which is going to be

33
00:01:24,410 --> 00:01:27,050
called the gun or

34
00:01:27,050 --> 00:01:32,810
let's call it the weapons system.

35
00:01:32,810 --> 00:01:34,510
Have Enter.

36
00:01:34,505 --> 00:01:36,095
And I'm going to create

37
00:01:36,095 --> 00:01:37,645
a script in here which is going to

38
00:01:37,640 --> 00:01:42,550
be the weapons system.

39
00:01:42,545 --> 00:01:47,345
Hit Enter, wait for it to compile.

40
00:01:47,345 --> 00:01:51,835
And there we go.

41
00:01:51,830 --> 00:01:54,680
And a day now. Thank you.

42
00:01:54,680 --> 00:01:56,350
It was just a script.

43
00:01:56,345 --> 00:01:58,135
Anyways, I'm going to make

44
00:01:58,130 --> 00:02:01,210
the fire point a child of the shotgun,

45
00:02:01,205 --> 00:02:04,255
and it won't allow us will need to open the prefab.

46
00:02:04,250 --> 00:02:07,250
There we go, make it a child, save that.

47
00:02:07,250 --> 00:02:10,010
Go back into our game. There we go.

48
00:02:10,010 --> 00:02:11,750
So now we have, and sometimes when

49
00:02:11,750 --> 00:02:13,640
you want to add the prefabs,

50
00:02:13,640 --> 00:02:16,540
make child of things and make parents.

51
00:02:16,535 --> 00:02:18,265
Sometimes it will require you

52
00:02:18,260 --> 00:02:23,760
to the extra step of actually changing the whole prefab.

53
00:02:23,764 --> 00:02:25,134
And the next thing we're going to

54
00:02:25,130 --> 00:02:26,420
do is we're going to add

55
00:02:26,420 --> 00:02:29,270
this weapon system to the actual shotgun.

56
00:02:29,270 --> 00:02:32,740
So now the shotgun will handle all the shooting.

57
00:02:32,735 --> 00:02:35,255
First of all, let's open up the weapons system.

58
00:02:35,255 --> 00:02:40,115
And if I look in the layer controller, where is it?

59
00:02:40,115 --> 00:02:41,525
Let's click in here.

60
00:02:41,525 --> 00:02:44,665
Whereas the player controller, okay, though.

61
00:02:44,660 --> 00:02:46,130
So there we go. As you can see,

62
00:02:46,130 --> 00:02:48,580
we have so many scripts right now.

63
00:02:48,575 --> 00:02:51,415
But anyways, what we want to do is we want to

64
00:02:51,410 --> 00:02:54,410
move and this should be a separate method.

65
00:02:54,410 --> 00:02:56,810
What we want to do is we want to move

66
00:02:56,810 --> 00:02:59,530
the whole player shooting mechanic

67
00:02:59,525 --> 00:03:02,575
from the player controller into the weapon system.

68
00:03:02,570 --> 00:03:05,350
I've maybe mentioned this before.

69
00:03:05,345 --> 00:03:08,155
We don't want the player to handle everything.

70
00:03:08,150 --> 00:03:10,070
So for example, we don't want

71
00:03:10,070 --> 00:03:12,530
the player to handle how bullets fly,

72
00:03:12,530 --> 00:03:16,510
and we don't want the player to handle how weapons work.

73
00:03:16,505 --> 00:03:18,425
So with that said,

74
00:03:18,425 --> 00:03:20,765
I'm going to issue you a challenge.

75
00:03:20,765 --> 00:03:23,075
And your challenge is going to be to move

76
00:03:23,075 --> 00:03:25,835
the firing to the proper script.

77
00:03:25,835 --> 00:03:28,105
So couple of the firing method from

78
00:03:28,100 --> 00:03:30,670
player controller to the gun system script.

79
00:03:30,665 --> 00:03:34,915
Make sure the two copy all the proper variables with it,

80
00:03:34,910 --> 00:03:37,640
and set everything in unity and test it out,

81
00:03:37,640 --> 00:03:39,740
make sure it works properly.

82
00:03:39,740 --> 00:03:41,890
So this challenge is just

83
00:03:41,885 --> 00:03:45,835
about how you upgrade your script,

84
00:03:45,830 --> 00:03:48,130
how you upgrade your project and gain.

85
00:03:48,125 --> 00:03:50,615
Sometimes you start off your project.

86
00:03:50,615 --> 00:03:53,395
You don't have the entire big plan for it,

87
00:03:53,390 --> 00:03:55,220
so you need to make adjustments.

88
00:03:55,220 --> 00:03:57,470
This will just be an exercise in

89
00:03:57,470 --> 00:03:59,950
how to transfer things from one script,

90
00:03:59,945 --> 00:04:01,405
the next, making it better,

91
00:04:01,400 --> 00:04:02,510
I'll do it in front of you,

92
00:04:02,510 --> 00:04:03,730
so don't worry about it.

93
00:04:03,725 --> 00:04:06,235
We'll we'll make sure that everything works properly.

94
00:04:06,230 --> 00:04:11,330
But for now, pause the video and go do the challenge.

95
00:04:11,330 --> 00:04:13,760
Oh, okay, welcome back.

96
00:04:13,760 --> 00:04:17,090
So what are we going to be doing in here?

97
00:04:17,090 --> 00:04:21,130
We are going to go ahead and select all of this.

98
00:04:21,125 --> 00:04:25,075
I'm going to cut so Control X. I'm

99
00:04:25,070 --> 00:04:29,030
going to go ahead and put it in here or know what,

100
00:04:29,030 --> 00:04:30,620
let's keep the update and start.

101
00:04:30,620 --> 00:04:32,300
We might need them. I'm going

102
00:04:32,300 --> 00:04:34,250
to paste everything in here so you can

103
00:04:34,250 --> 00:04:38,710
see we have a lot that we need to handle.

104
00:04:38,705 --> 00:04:40,675
So back in here,

105
00:04:40,670 --> 00:04:42,850
we will need a couple of

106
00:04:42,845 --> 00:04:46,355
variables which are, let me go up.

107
00:04:46,355 --> 00:04:48,485
First of all, I'm going to

108
00:04:48,485 --> 00:04:51,055
comment this one out, save that.

109
00:04:51,050 --> 00:04:54,290
Then I'm going to check in here, what do we need?

110
00:04:54,290 --> 00:04:57,560
We need the swap and automatic the bullet the far point.

111
00:04:57,560 --> 00:04:58,160
Okay.

112
00:04:58,160 --> 00:05:02,900
So let's see as weapon automatic time between shots,

113
00:05:02,900 --> 00:05:05,440
shots countered, fire point. There he goes.

114
00:05:05,435 --> 00:05:06,925
These are.

115
00:05:06,920 --> 00:05:11,330
Variables and I'm going to paste them in here.

116
00:05:11,330 --> 00:05:12,010
Save that.

117
00:05:12,005 --> 00:05:13,525
Let's see what else do we have?

118
00:05:13,520 --> 00:05:15,610
Do we have some kind of error here?

119
00:05:15,605 --> 00:05:18,965
Nope, I don't think that was all the mechanics.

120
00:05:18,965 --> 00:05:21,005
So back in here, what else do we have?

121
00:05:21,005 --> 00:05:23,785
0. So if the player can dash, now,

122
00:05:23,780 --> 00:05:26,720
obviously the dashing is part of

123
00:05:26,720 --> 00:05:27,970
the player mechanics of

124
00:05:27,970 --> 00:05:30,470
the player is the one that is going to dash.

125
00:05:30,470 --> 00:05:32,980
So what we'll need is a way for

126
00:05:32,975 --> 00:05:35,515
us to get a reference to the dash.

127
00:05:35,510 --> 00:05:38,110
So is the player dashing or not?

128
00:05:38,105 --> 00:05:39,215
What we can do?

129
00:05:39,215 --> 00:05:40,895
If we scroll down here,

130
00:05:40,895 --> 00:05:43,045
we can create a method.

131
00:05:43,040 --> 00:05:44,750
And if I look up here,

132
00:05:44,750 --> 00:05:46,780
the dash you can see as private.

133
00:05:46,775 --> 00:05:50,695
And what we can do is we can create a method in here.

134
00:05:50,690 --> 00:05:53,720
And these are things that we are going to be using

135
00:05:53,720 --> 00:05:56,830
more and more as we go this type of method.

136
00:05:56,825 --> 00:06:05,605
So it's a public bool and is layer dashing.

137
00:06:05,600 --> 00:06:08,290
So in here, all that you are going to do

138
00:06:08,285 --> 00:06:11,935
is return can dash.

139
00:06:11,930 --> 00:06:14,900
And I'll add an exclamation mark

140
00:06:14,900 --> 00:06:17,290
because remember how the dashes working.

141
00:06:17,285 --> 00:06:19,535
And because we only return one thing,

142
00:06:19,535 --> 00:06:22,255
this is how we are going to be writing it.

143
00:06:22,250 --> 00:06:24,200
Now, obviously this is not something

144
00:06:24,200 --> 00:06:26,090
that is like a standard.

145
00:06:26,090 --> 00:06:28,400
This is more like practices.

146
00:06:28,400 --> 00:06:31,340
So have some kind of

147
00:06:31,340 --> 00:06:33,860
variable in some different script

148
00:06:33,860 --> 00:06:35,230
that you want to access.

149
00:06:35,225 --> 00:06:36,985
How do you do it?

150
00:06:36,980 --> 00:06:40,120
Well, you either make the variable public,

151
00:06:40,115 --> 00:06:42,235
you make it accessible to everybody.

152
00:06:42,230 --> 00:06:43,940
But the problem when making it

153
00:06:43,940 --> 00:06:46,630
public is that you can change.

154
00:06:46,625 --> 00:06:48,335
So if I make this public,

155
00:06:48,335 --> 00:06:51,485
I can then change it from a different script,

156
00:06:51,485 --> 00:06:53,485
which is a very bad idea.

157
00:06:53,480 --> 00:06:56,600
Trust me, you never want to be able to change

158
00:06:56,600 --> 00:07:00,290
variables in different scripts from different scripts.

159
00:07:00,290 --> 00:07:01,730
So you don't want to be able to

160
00:07:01,730 --> 00:07:03,500
make the player dash from,

161
00:07:03,500 --> 00:07:05,570
let's say, the UI Manager by

162
00:07:05,570 --> 00:07:07,790
mistake, it happens sometimes.

163
00:07:07,790 --> 00:07:10,580
So a better way is to just be able to

164
00:07:10,580 --> 00:07:14,510
check if we are dashing so we can get the dashing,

165
00:07:14,510 --> 00:07:17,270
but we cannot change whether the player is dashing.

166
00:07:17,270 --> 00:07:20,630
So this is an extra layer of safety and

167
00:07:20,630 --> 00:07:24,130
this is why we always use serialized fields.

168
00:07:24,125 --> 00:07:26,375
We could have made them all public

169
00:07:26,375 --> 00:07:28,865
and it would have been the same functions.

170
00:07:28,865 --> 00:07:31,235
We could have seen them in the inspector and so on.

171
00:07:31,235 --> 00:07:34,225
But making it a serialized field means that we

172
00:07:34,220 --> 00:07:37,880
cannot access these variables from different scripts,

173
00:07:37,880 --> 00:07:40,150
and this will pay dividends later on

174
00:07:40,145 --> 00:07:42,725
as you go in your game development journey.

175
00:07:42,725 --> 00:07:44,605
Making sure that you can,

176
00:07:44,600 --> 00:07:46,250
not only in game development,

177
00:07:46,250 --> 00:07:47,900
whenever it comes to programming,

178
00:07:47,900 --> 00:07:50,240
you don't want different classes,

179
00:07:50,240 --> 00:07:53,260
changing variables, other different classes.

180
00:07:53,255 --> 00:07:55,355
Anyways, I'm getting ahead of myself.

181
00:07:55,355 --> 00:07:57,005
What are we going to do in here?

182
00:07:57,005 --> 00:07:59,405
We can either find the player object

183
00:07:59,405 --> 00:08:02,635
or we can get component in parent.

184
00:08:02,630 --> 00:08:07,760
And we can, let's remove this for a second.

185
00:08:07,760 --> 00:08:11,530
We can access the player controller and the parent,

186
00:08:11,525 --> 00:08:13,655
and we can go ahead and check.

187
00:08:13,655 --> 00:08:17,785
Is player is player dashing or what,

188
00:08:17,780 --> 00:08:20,900
what's this player is dashing.

189
00:08:20,899 --> 00:08:25,869
What's this layer is dashing, is moving.

190
00:08:25,865 --> 00:08:27,595
There is dashing 0,

191
00:08:27,590 --> 00:08:30,340
so we can actually also return this.

192
00:08:30,335 --> 00:08:34,235
So this method is no longer needed.

193
00:08:34,230 --> 00:08:38,080
And that was really not something that I noticed.

194
00:08:38,080 --> 00:08:40,870
But anyways, layer is dashing.

195
00:08:40,869 --> 00:08:43,229
At least we had the opportunity.

196
00:08:43,225 --> 00:08:44,625
Let's just double-check if

197
00:08:44,620 --> 00:08:47,500
the current movement speed is equal to the speed.

198
00:08:47,500 --> 00:08:50,530
Okay, so we return true. And there we go.

199
00:08:50,530 --> 00:08:51,750
If we are dashing,

200
00:08:51,745 --> 00:08:53,715
then we cannot be shooting

201
00:08:53,710 --> 00:08:55,930
and will not call this the player shooting.

202
00:08:55,930 --> 00:09:00,460
Let's changes to the firing bullets.

203
00:09:00,460 --> 00:09:03,810
There we go. So this makes more sense right now.

204
00:09:03,805 --> 00:09:05,565
And what else should we be doing?

205
00:09:05,560 --> 00:09:07,150
Well, obviously, we need to be

206
00:09:07,150 --> 00:09:08,980
calling it in here in the update,

207
00:09:08,980 --> 00:09:11,160
making sure that we can shoot.

208
00:09:11,155 --> 00:09:13,215
So I'm going to be simply calling

209
00:09:13,210 --> 00:09:18,040
the firing bullets method.

210
00:09:18,035 --> 00:09:20,485
And now we need to go back

211
00:09:20,480 --> 00:09:22,790
into Unity and set everything up.

212
00:09:22,790 --> 00:09:25,180
So I'm going to open up Unity.

213
00:09:25,175 --> 00:09:28,085
You'll see that the weapon system changed.

214
00:09:28,085 --> 00:09:31,075
And this was, this is so embarrassing.

215
00:09:31,070 --> 00:09:33,550
I didn't even notice it was just there and

216
00:09:33,545 --> 00:09:37,025
I completely forgot that we had displayed this dashing.

217
00:09:37,025 --> 00:09:38,665
But anyways, at least you learn

218
00:09:38,660 --> 00:09:40,370
something a different type.

219
00:09:40,370 --> 00:09:43,130
Or we have this little monologue of why

220
00:09:43,130 --> 00:09:47,170
we don't want access to the variables.

221
00:09:47,165 --> 00:09:48,955
Now, no worries. Electron of

222
00:09:48,950 --> 00:09:50,930
course we will be implementing a lot of

223
00:09:50,930 --> 00:09:52,990
these methods as we move forward

224
00:09:52,985 --> 00:09:55,415
and make our code a bit more professional.

225
00:09:55,415 --> 00:09:58,795
So with that, who Things Done?

226
00:09:58,790 --> 00:10:00,460
Let's go in to,

227
00:10:00,455 --> 00:10:03,755
first of all as 70 far point of the shotgun.

228
00:10:03,755 --> 00:10:05,575
We are going to make sure

229
00:10:05,570 --> 00:10:07,370
that this weapon is not a romantic and we'll

230
00:10:07,370 --> 00:10:12,040
make the time between shots around 1 second, 1, not 21.

231
00:10:12,035 --> 00:10:15,205
We need a bullet, so we'll go into the Prefabs,

232
00:10:15,200 --> 00:10:18,640
broken bullets, and the layer bullets.

233
00:10:18,635 --> 00:10:19,825
Save that.

234
00:10:19,820 --> 00:10:23,920
Let's go into the doom player and apply all the changes.

235
00:10:23,915 --> 00:10:27,815
And now I'm going to What else do we have?

236
00:10:27,814 --> 00:10:30,364
Let's run the game and see what happens.

237
00:10:30,365 --> 00:10:34,735
So the player, player moves around way,

238
00:10:34,730 --> 00:10:38,050
but so the player moves around and if we should,

239
00:10:38,045 --> 00:10:40,115
There we go, we can shoot.

240
00:10:40,115 --> 00:10:42,305
And if I hold down the mouse button,

241
00:10:42,305 --> 00:10:44,855
for some reason, it's not shooting.

242
00:10:44,855 --> 00:10:47,995
123.

243
00:10:47,990 --> 00:10:49,310
Oh, it's not automatic.

244
00:10:49,310 --> 00:10:49,810
Okay.

245
00:10:49,805 --> 00:10:51,415
But the problem is so okay.

246
00:10:51,410 --> 00:10:54,970
Now, even though I hold down the mouse button,

247
00:10:54,965 --> 00:10:58,885
it's not automatic, but the shotgun still fires a lot.

248
00:10:58,880 --> 00:11:01,220
And this is something we want to fix because we are

249
00:11:01,220 --> 00:11:04,000
now talking about an advanced shooting mechanic.

250
00:11:03,995 --> 00:11:06,505
It's not the usual shooting mechanic.

251
00:11:06,500 --> 00:11:09,730
We need to make sure that our shooting is consistent.

252
00:11:09,725 --> 00:11:11,915
So the shotgun, if we hold down,

253
00:11:11,915 --> 00:11:13,135
it shoots one button,

254
00:11:13,130 --> 00:11:15,620
but if we keep pushing so the shotgun shouldn't

255
00:11:15,620 --> 00:11:18,110
be firing so much when shooting.

256
00:11:18,110 --> 00:11:19,960
So with that out of the way,

257
00:11:19,955 --> 00:11:26,245
with this whole section, Change, scripting everything.

258
00:11:26,240 --> 00:11:29,560
I hope you enjoy it and I'll see you in the next video.

259
00:11:29,555 --> 00:11:34,075
Make sure that you always commit your changes.

260
00:11:34,070 --> 00:11:36,310
And I'm going to make this commit

261
00:11:36,305 --> 00:11:42,005
move shooting mechanic from

262
00:11:42,004 --> 00:11:47,934
layer two, the actual weapon.

263
00:11:47,930 --> 00:11:50,920
There we go, commit the changes,

264
00:11:50,915 --> 00:11:53,735
and I'll see you in the next video.

