Welcome back my fellow game developers
to another maintenance video.
I know it's not the most fun parts of video,
but it is very important and there are
crucial lessons that we need to learn and this one.
So now when we run the game,
you'll see that we no longer have the option to
create an automatic automatic weapon.
But now, if we hold down the button,
you can see that we should 11111.
And if we try to press
as much as we can, listen to the mouse,
you can see that we no longer have the option to shoot or
to bypass this mechanic of taking the time between shots.
So let's not waste any more time and let's get
to maintaining 0 case.
So this is another video where we want to fix our things.
So the first thing we want to fix
is let's look at the shotgun.
So let's say it is not automatic.
So a shoot.
And there you go. We have one shot.
If I'll keep holding it down, it doesn't work.
But the problem is if I press a lot of times,
you can see that we have a lot of shops.
Now, this is not a huge problem,
but for example, a shotgun
shouldn't be shooting that fast.
If we make it automatic and keep holding down,
you can see that we keep shooting everyone second.
And if we try to press a lot of times,
this is not a problem.
But we still need to fix
the fact that if we don't have the weapon automatic,
we should as much as we want.
Another thing that we want to
fix is the redundancy in the code.
So this is not a perfect way to represent the code.
There is a much better way.
We can first of all,
relieve ourselves of one of the problems of
having to choose between
automatic and non-aromatic so we can,
first of all get rid of one variable.
And the second thing that we can
avoid, redundancy and cold.
So you can see right here that we
have the score that instantiates
a bullet and this one that also instantiates or Ebola.
So it's not that good.
We want to make something much
more efficient, much better looking.
So I'm going to comment these out.
And in here I'm going to check for something different.
I'm going to start off by checking if
the shot counter is greater than 0.
So if the shot counter is greater than 0,
then what we'll do is we are going to keep
the shop counter being removed every little bit.
So we are going to be counting down the shop counter.
And because recall this in the firing bullets,
that means this is going to work fine.
Then in here, we are going to check for the inputs.
And if these inputs are true,
then we are going to instantiate the bullet.
So what I'm going to do is I'm going to
issue it to you as a challenge.
So your challenge is to make sure
we check for both inputs,
whether we're holding down or we're pressing only once.
And then we are going to
instantiate the bullet and make sure
to also reset the shot counter.
So pause the video right now and go do the challenge.
Oh, okay, welcome back.
So in here the first thing that I'm
going to do is create the if statement.
And I'm going to copy this line right here.
So if input dot get mouse button down,
or where is it,
Okay, so, or, or as represented by these two.
Or if the input dot get mouse button.
So we are holding noun,
then we are going to go ahead and
instantiate the bullet on the fire point.
And we are going to also get
the shot counter and reset it to the time between shots.
There you go. So what happens in here?
We are always calling the firing,
but we check if the player is dashing.
If it's not, then we are going to continue.
If the shot counter is greater than 0,
then we are going to be counting down all the
time and when it does get below 0.
So we are going to keep counting
down as long as it's shut counter is greater than 0.
When it's not anymore,
then we will have the option to shoot.
And the great thing about this is
whether the weapon is automatic or not.
If we keep holding down,
we will not be able to shoot all the time.
But if it's not automatic and we
only use the finger to press it once,
twice or three times,
we are going to instantiate and we will have
the counter reset every single time when we should,
once it will stop and wait for the
short countered to come back to less than 0,
then we can shoot and as much as we want.
So the only thing here is that we no
longer check if the weapon is automatic or not.
So we can go ahead and delete this.
We created some sort of shortcut.
Now, if you don't like this,
if you are looking,
that's what I comment this whole code out.
If you want to have
an automatic weapon and it
doesn't bother you, allow that?
We can shoot as much as we
want because at the end of the day,
if it is automatic, it won't be shooting very fast.
Then be my guest.
Keeps cold. It's not bad.
But for me, honestly, I don't want this.
I would much rather have this as
a very simple code and
have us save a couple of variables.
So and I a couple of redundant code also,
which is very important.
So we saved all of this.
We go back into Unity.
We will run the game and
now the time between shots is reduced.
So now even if we cook a lot of times,
you can see that it keeps
waiting until the short counter is reset.
If we hold it down, There you go.
You can see that every single second we let out a shot.
If we make this, for example,
let's say 0.1, then we
can go ahead and shoot multiple times.
And if we press as fast as we promised,
we will never be faster than what
the shot counter will ever allow us to be.
So with that done, I hope you enjoyed.
And in the next video we'll be adding
different weapons to the player.
And you'll see how having something
different than a shotgun will really
make the code much more visible or the changes that we
made much more important if you
still don't feel it's that good.
So I'll see you then.