1
00:00:00,000 --> 00:00:02,880
Welcome back my fellow game developers

2
00:00:02,880 --> 00:00:05,120
to another maintenance video.

3
00:00:05,115 --> 00:00:07,865
I know it's not the most fun parts of video,

4
00:00:07,860 --> 00:00:10,140
but it is very important and there are

5
00:00:10,140 --> 00:00:12,980
crucial lessons that we need to learn and this one.

6
00:00:12,975 --> 00:00:14,745
So now when we run the game,

7
00:00:14,745 --> 00:00:16,835
you'll see that we no longer have the option to

8
00:00:16,830 --> 00:00:19,200
create an automatic automatic weapon.

9
00:00:19,200 --> 00:00:22,110
But now, if we hold down the button,

10
00:00:22,110 --> 00:00:25,140
you can see that we should 11111.

11
00:00:25,140 --> 00:00:27,000
And if we try to press

12
00:00:27,000 --> 00:00:29,500
as much as we can, listen to the mouse,

13
00:00:29,500 --> 00:00:34,460
you can see that we no longer have the option to shoot or

14
00:00:34,460 --> 00:00:39,230
to bypass this mechanic of taking the time between shots.

15
00:00:39,230 --> 00:00:42,160
So let's not waste any more time and let's get

16
00:00:42,155 --> 00:00:45,355
to maintaining 0 case.

17
00:00:45,350 --> 00:00:50,650
So this is another video where we want to fix our things.

18
00:00:50,645 --> 00:00:52,625
So the first thing we want to fix

19
00:00:52,625 --> 00:00:54,625
is let's look at the shotgun.

20
00:00:54,620 --> 00:00:57,080
So let's say it is not automatic.

21
00:00:57,079 --> 00:00:58,449
So a shoot.

22
00:00:58,445 --> 00:01:00,055
And there you go. We have one shot.

23
00:01:00,050 --> 00:01:02,090
If I'll keep holding it down, it doesn't work.

24
00:01:02,090 --> 00:01:04,940
But the problem is if I press a lot of times,

25
00:01:04,940 --> 00:01:07,370
you can see that we have a lot of shops.

26
00:01:07,370 --> 00:01:10,130
Now, this is not a huge problem,

27
00:01:10,130 --> 00:01:11,810
but for example, a shotgun

28
00:01:11,810 --> 00:01:13,880
shouldn't be shooting that fast.

29
00:01:13,880 --> 00:01:16,310
If we make it automatic and keep holding down,

30
00:01:16,310 --> 00:01:18,850
you can see that we keep shooting everyone second.

31
00:01:18,845 --> 00:01:20,915
And if we try to press a lot of times,

32
00:01:20,915 --> 00:01:22,625
this is not a problem.

33
00:01:22,625 --> 00:01:24,415
But we still need to fix

34
00:01:24,410 --> 00:01:27,160
the fact that if we don't have the weapon automatic,

35
00:01:27,155 --> 00:01:29,005
we should as much as we want.

36
00:01:29,000 --> 00:01:30,830
Another thing that we want to

37
00:01:30,830 --> 00:01:33,410
fix is the redundancy in the code.

38
00:01:33,410 --> 00:01:36,800
So this is not a perfect way to represent the code.

39
00:01:36,800 --> 00:01:38,720
There is a much better way.

40
00:01:38,720 --> 00:01:40,430
We can first of all,

41
00:01:40,430 --> 00:01:43,610
relieve ourselves of one of the problems of

42
00:01:43,610 --> 00:01:45,020
having to choose between

43
00:01:45,020 --> 00:01:47,320
automatic and non-aromatic so we can,

44
00:01:47,315 --> 00:01:49,985
first of all get rid of one variable.

45
00:01:49,985 --> 00:01:51,845
And the second thing that we can

46
00:01:51,845 --> 00:01:53,995
avoid, redundancy and cold.

47
00:01:53,990 --> 00:01:55,490
So you can see right here that we

48
00:01:55,490 --> 00:01:57,200
have the score that instantiates

49
00:01:57,200 --> 00:02:00,530
a bullet and this one that also instantiates or Ebola.

50
00:02:00,530 --> 00:02:02,800
So it's not that good.

51
00:02:02,795 --> 00:02:04,615
We want to make something much

52
00:02:04,610 --> 00:02:06,710
more efficient, much better looking.

53
00:02:06,710 --> 00:02:09,590
So I'm going to comment these out.

54
00:02:09,590 --> 00:02:12,680
And in here I'm going to check for something different.

55
00:02:12,680 --> 00:02:14,810
I'm going to start off by checking if

56
00:02:14,810 --> 00:02:17,690
the shot counter is greater than 0.

57
00:02:17,690 --> 00:02:23,000
So if the shot counter is greater than 0,

58
00:02:23,000 --> 00:02:25,910
then what we'll do is we are going to keep

59
00:02:25,910 --> 00:02:31,660
the shop counter being removed every little bit.

60
00:02:31,655 --> 00:02:35,155
So we are going to be counting down the shop counter.

61
00:02:35,150 --> 00:02:37,340
And because recall this in the firing bullets,

62
00:02:37,340 --> 00:02:40,010
that means this is going to work fine.

63
00:02:40,010 --> 00:02:44,740
Then in here, we are going to check for the inputs.

64
00:02:44,735 --> 00:02:46,475
And if these inputs are true,

65
00:02:46,475 --> 00:02:48,895
then we are going to instantiate the bullet.

66
00:02:48,890 --> 00:02:51,190
So what I'm going to do is I'm going to

67
00:02:51,185 --> 00:02:53,645
issue it to you as a challenge.

68
00:02:53,645 --> 00:02:55,585
So your challenge is to make sure

69
00:02:55,580 --> 00:02:57,470
we check for both inputs,

70
00:02:57,470 --> 00:03:01,120
whether we're holding down or we're pressing only once.

71
00:03:01,115 --> 00:03:02,585
And then we are going to

72
00:03:02,585 --> 00:03:04,315
instantiate the bullet and make sure

73
00:03:04,310 --> 00:03:07,310
to also reset the shot counter.

74
00:03:07,310 --> 00:03:11,930
So pause the video right now and go do the challenge.

75
00:03:11,930 --> 00:03:14,420
Oh, okay, welcome back.

76
00:03:14,420 --> 00:03:16,580
So in here the first thing that I'm

77
00:03:16,580 --> 00:03:19,090
going to do is create the if statement.

78
00:03:19,085 --> 00:03:22,015
And I'm going to copy this line right here.

79
00:03:22,010 --> 00:03:25,240
So if input dot get mouse button down,

80
00:03:25,235 --> 00:03:28,315
or where is it,

81
00:03:28,310 --> 00:03:31,990
Okay, so, or, or as represented by these two.

82
00:03:31,985 --> 00:03:35,135
Or if the input dot get mouse button.

83
00:03:35,135 --> 00:03:36,985
So we are holding noun,

84
00:03:36,980 --> 00:03:39,400
then we are going to go ahead and

85
00:03:39,395 --> 00:03:42,955
instantiate the bullet on the fire point.

86
00:03:42,950 --> 00:03:45,230
And we are going to also get

87
00:03:45,230 --> 00:03:50,270
the shot counter and reset it to the time between shots.

88
00:03:50,270 --> 00:03:53,030
There you go. So what happens in here?

89
00:03:53,030 --> 00:03:54,980
We are always calling the firing,

90
00:03:54,980 --> 00:03:57,980
but we check if the player is dashing.

91
00:03:57,980 --> 00:04:00,800
If it's not, then we are going to continue.

92
00:04:00,800 --> 00:04:03,400
If the shot counter is greater than 0,

93
00:04:03,395 --> 00:04:06,025
then we are going to be counting down all the

94
00:04:06,020 --> 00:04:09,380
time and when it does get below 0.

95
00:04:09,380 --> 00:04:11,510
So we are going to keep counting

96
00:04:11,510 --> 00:04:14,560
down as long as it's shut counter is greater than 0.

97
00:04:14,555 --> 00:04:15,935
When it's not anymore,

98
00:04:15,935 --> 00:04:18,385
then we will have the option to shoot.

99
00:04:18,380 --> 00:04:20,420
And the great thing about this is

100
00:04:20,420 --> 00:04:22,700
whether the weapon is automatic or not.

101
00:04:22,700 --> 00:04:24,170
If we keep holding down,

102
00:04:24,170 --> 00:04:26,710
we will not be able to shoot all the time.

103
00:04:26,705 --> 00:04:29,185
But if it's not automatic and we

104
00:04:29,180 --> 00:04:31,580
only use the finger to press it once,

105
00:04:31,580 --> 00:04:33,130
twice or three times,

106
00:04:33,125 --> 00:04:35,845
we are going to instantiate and we will have

107
00:04:35,840 --> 00:04:38,960
the counter reset every single time when we should,

108
00:04:38,960 --> 00:04:41,120
once it will stop and wait for the

109
00:04:41,120 --> 00:04:43,730
short countered to come back to less than 0,

110
00:04:43,730 --> 00:04:46,430
then we can shoot and as much as we want.

111
00:04:46,430 --> 00:04:48,770
So the only thing here is that we no

112
00:04:48,770 --> 00:04:52,220
longer check if the weapon is automatic or not.

113
00:04:52,220 --> 00:04:54,250
So we can go ahead and delete this.

114
00:04:54,245 --> 00:04:56,795
We created some sort of shortcut.

115
00:04:56,795 --> 00:04:58,645
Now, if you don't like this,

116
00:04:58,640 --> 00:05:00,830
if you are looking,

117
00:05:00,830 --> 00:05:03,460
that's what I comment this whole code out.

118
00:05:03,455 --> 00:05:04,925
If you want to have

119
00:05:04,925 --> 00:05:06,685
an automatic weapon and it

120
00:05:06,680 --> 00:05:08,870
doesn't bother you, allow that?

121
00:05:08,870 --> 00:05:10,130
We can shoot as much as we

122
00:05:10,130 --> 00:05:11,270
want because at the end of the day,

123
00:05:11,270 --> 00:05:14,050
if it is automatic, it won't be shooting very fast.

124
00:05:14,045 --> 00:05:15,335
Then be my guest.

125
00:05:15,335 --> 00:05:17,245
Keeps cold. It's not bad.

126
00:05:17,240 --> 00:05:20,560
But for me, honestly, I don't want this.

127
00:05:20,555 --> 00:05:23,165
I would much rather have this as

128
00:05:23,165 --> 00:05:25,585
a very simple code and

129
00:05:25,580 --> 00:05:28,070
have us save a couple of variables.

130
00:05:28,070 --> 00:05:30,950
So and I a couple of redundant code also,

131
00:05:30,950 --> 00:05:32,090
which is very important.

132
00:05:32,090 --> 00:05:33,940
So we saved all of this.

133
00:05:33,935 --> 00:05:35,465
We go back into Unity.

134
00:05:35,465 --> 00:05:37,225
We will run the game and

135
00:05:37,220 --> 00:05:39,260
now the time between shots is reduced.

136
00:05:39,260 --> 00:05:41,630
So now even if we cook a lot of times,

137
00:05:41,630 --> 00:05:43,360
you can see that it keeps

138
00:05:43,355 --> 00:05:46,435
waiting until the short counter is reset.

139
00:05:46,430 --> 00:05:48,500
If we hold it down, There you go.

140
00:05:48,500 --> 00:05:51,800
You can see that every single second we let out a shot.

141
00:05:51,800 --> 00:05:53,240
If we make this, for example,

142
00:05:53,240 --> 00:05:55,040
let's say 0.1, then we

143
00:05:55,040 --> 00:05:57,080
can go ahead and shoot multiple times.

144
00:05:57,080 --> 00:05:59,450
And if we press as fast as we promised,

145
00:05:59,450 --> 00:06:01,940
we will never be faster than what

146
00:06:01,940 --> 00:06:04,690
the shot counter will ever allow us to be.

147
00:06:04,685 --> 00:06:07,105
So with that done, I hope you enjoyed.

148
00:06:07,100 --> 00:06:09,080
And in the next video we'll be adding

149
00:06:09,080 --> 00:06:11,300
different weapons to the player.

150
00:06:11,300 --> 00:06:13,160
And you'll see how having something

151
00:06:13,160 --> 00:06:15,290
different than a shotgun will really

152
00:06:15,290 --> 00:06:18,890
make the code much more visible or the changes that we

153
00:06:18,890 --> 00:06:20,840
made much more important if you

154
00:06:20,840 --> 00:06:23,060
still don't feel it's that good.

155
00:06:23,060 --> 00:06:25,470
So I'll see you then.

