Welcome back, My favorite game developers.
In this video, we've actually started adding the shotgun,
rifle and the pistil,
which are the weapons to our weapons available.
So now when we run the game,
you'll notice that when we all,
we also added a bit of rotation,
which makes our game much cooler.
So now when I pick up the shotgun, there we go.
You can see that I get the shot gun in my hand.
Not only that, if I go into the doom player,
you can see that it's already in here.
And not only that, when I pick up the pistol,
for example, There we go.
You can see that even though it's destroyed,
not actually pick it up.
And finally, the rifle and pick it up.
It's here in our weapons,
are in our available weapons.
We can switch between it,
it does this which automatically, how cool is that?
All mechanics are perfect.
So let's, let's not waste
any more time and let's get started.
Oh, okay.
So while you were moving between
videos and leaving reviews
for me because it helps me out a lot.
I've created two more weapons,
pickup 14, the pistol 14 the rifle,
and obviously it's very easy.
All I did is just duplicate the shotgun,
pick up at the sprite
and add the weapon and the weapons pickup.
So I'm going to go into the Prefabs,
let's see and hear the pickups.
And let's call this the folder or you know what,
What do that just lets the shotguns,
pistol, rifle save that.
Great. Now the next step is to actually
start adding in the player to the available weapons.
So we'll need to create some kind of method to do that.
And it's going to be your challenge to
create a method that adds to the available guns.
So you'll need to create a method that takes a parameter,
the cons to add,
the gun to add,
or the weapon to add whatever you wanna call it,
need to add it to the list of available guns or weapons.
Then I'm going to give you a small hint
of how you can add to
any list that you have and just use
the dot add with inside of it.
You can also go through the documentations of I've
left you the list of documentation on
how to dot to a list.
So pause the video right now and go do the challenge.
Okay, welcome back.
How did you get on with that?
So I'm going to go ahead and scroll down.
And in here.
And we keep these methods
alone and we create methods in here.
This is just an organization criteria for me,
maybe you have something different and ways.
Public void.
Add two available weapons and open up the brackets,
as I've said, the sticks and weapons weapons system.
And we have the weapon to add.
Open up the circles right here.
And we are simply going to get the available,
opens the ad, and we have the weapon to add.
There we go. That's all that we needed to do.
And finally, when we
actually do pick up the weapon in here,
we instantiate the weapon.
We also get the collision get
component, the layer controller.
And we add two available weapons.
What do we add? Well, we want to add
the weapon that we've created in here.
So I'm going to get
a reference to the swapping is going to be
of type weapons system.
There we go and view weapon to add is equal to this.
So weapon to add,
save that back in our game.
Let's run this.
And they now,
any day now run this.
And now we should see that we have the pistol and he,
they now come on.
And finally we have the pistil.
Now we pick up the shotgun so we can see that we can
switch to the shotgun right here
and you can see it in the available weapons.
Finally, we tried to pick up the pistol.
As you can see, we don't get the pistol,
we only get the shotgun and now we pick up the rifle.
We have the rifle.
We can switch between them.
And as you can see right here, now,
there was a slight problem
that you might have not noticed.
First of all, when I run the game,
let me just show you this again.
So when I pick up the shotgun, Okay, That's good.
I have the shotgun was me.
But when I pick up the rifle,
you can see that as soon as I start shooting,
first of all, we have the pistol and the rifle.
Both working, then I need
to somehow switch between them to pick it up.
So this is something that we will need to fix.
And to do that, I'm going to go back in the visit.
So at the available weapons.
And in here I'm going to make sure to
set the current gun and what it should be.
So set the current gun.
And what does it have to be?
Well, I'm just going to write it and then I will explain.
So the available weapons dot count minus2,
and then I'm going to switch the gun.
Okay?
And by the way, switch the gun. Which one is it?
Which?
Okay, So switching.
So as you can see,
this will not be working.
Why? Because the switch gone
actually requires us to press the Tab key.
So if we access this method
and try to use the Tab key, it will not work.
So what we're going to do is instead we
are going to extract this entire method.
Right-click in here.
Quick action and refactoring, extract the method.
And this will be the,
let's just call it actual gun switch.
Apply the change, save that.
So now we can actually do the actual guns switch in here.
And I hope that was clear why we did this.
Because again, that can just show you we have pups.
We tried to call the switch gun,
but the switch gun does not
work unless we press the Tab key.
So what we'll do is we'll
just extract this method in here.
So now the switch gone works completely fine.
But the only thing that we
have is we can actually switch the gut,
the actual gun switch.
So back in here,
where is it the actual can switch?
Why do we have the available weapon dot count minus two?
Let's first of all see if this actually works.
So back in our game,
we run the game.
And let's pick up the shotgun. There we go.
You can see the shotgun is
the only weapon that is working.
And now when we pick up the rifle, there we go.
The rightful is the only thing that was working.
And I press tab just
out of reactions or let's try this again.
Become the shotgun, pick up
the rifle is the only one working.
Great. Now back in here,
why do we have the available weapons dot count?
Let's think about this for a moment.
Let's say we pick up a weapon.
So let's say we had the pistil only,
we had 0, we had only one weapon and the count was one.
That pistol index was 0.
Let's say we pick up the shotgun.
So we pick up the shotgun.
Now we have the count equals to
2 and we have the shotgun at position 1.
So how are we going to actually
make sure that we only get the shotgun?
We'd get the available weapons dot count,
which is right now about two, will remove two.
That means we are at 0 and then we do
the actual switch and
the actual switch as soon as it starts.
If we look up here,
you can see that as soon as we start we
get the current gun plus, plus.
So we increased by one and this will work in any case.
So let's say we also picked up the rifle.
So now the count is 33 minus two is one.
That means we are at one,
which is the shotgun.
But when we actually do the switch gun, we increase.
We get two and we get the available shotgun.
I know. Confusing, isn't it?
You can rewatch what I said.
I'm pretty sure I've said everything correctly.
So this is just a way to make sure that
we always get the correct and proper cup.
So I hope you enjoyed in the next video,
we want to just add a bit more of, let's say, excitement.
Whenever we want to pick up a weapon,
we don't just want to have
the weapons lying around in our world.
We actually want to have are no,
maybe some kind of chest,
chest that will open up when we
get near it or press a certain button
when we are near it and then
have the weapon appear from it.
So I think I have a couple of minutes left in this video.
It's been short. So what I'm going do is I'm going to get
the rifle pickup or the shotgun pick up.
And I'm going to create an animation in here.
So just to make it a bit more
nice to ongoing to where is it, right-click in here.
Create a new weapons.
Backup. Hit Enter opening,
you're rotating weapon, row,
the thing, weapon, pick up.
And this is nothing new.
We're just going to do is you'll
see in just a bit for the thing,
weapon, pick up, save that.
So get the shotgun.
Stop recording.
And I want to have a rotation at around
the second one to be about this.
Yeah, sure.
So 90.
And at the second, second, second,
second, the rotation should be around 180.
There we go. And then add the second three.
We should be at 270, almost 70.
And finally on second four, we have 362.
Let's see how that looks.
Okay, seems good enough.
So this is the rotating weapon,
but we can also do a couple of
things right here if we choose all of them
right-click and you can see that we can
create some kind of tangent.
We can choose both tangent and make it maybe linear.
So now the rotation,
we'll just change a bit. There we go.
You can see that it keeps rotating, really nice.
We can also do the same and here.
So I'm going to leave the rest to you.
This is just a way to have a bit of a nicer game.
So now you can see that we have
this shotgun that we'll need to pick up.
There we go. We pick it up.
Everything is working perfectly fine.
So I hope you enjoy it.
I hope you are staging your files and I'll see you
in the next video where we create
a just opens up and gets us,
our puppets. See you then.
Hey, you thought you were rid of me, but no,
we still have a bit of time for something
and I was just worried
for one thing that you might want to go and
create an animation for every single weapon.
But no, you don't have
to go right here until the shotgun.
You can simply click on
these three little keys right here,
or buttons or whatever you wanna call them.
And you can see that you can actually
copy this entire component.
So when you copy it,
let me go back into the pistol.
I've already done this Remove
Component, room of components.
So on shotgun back in here,
we copy the component.
We go into the pistol pickup which does not rotate.
We click on any component that we want.
And you can see right here that we can
Paste Component as New.
So when I click on the Paste, there we go.
You can see that now it has
the controller of the shotgun.
And you might think right here that
maybe this is not a good idea.
We should have may be called
something different than the shotgun pickup,
but don't worry about it.
The thing that we are
looking for is the animation right here,
which only affects the rotation.
So it does not change the sprites,
it only affects the rotation of a game object.
So we won't have to worry about It's
sprites changing and this is a faster way for us.
Let's add that also to the rifle.
So this is a very fast way for us to
have rotating objects and not have
to create animations every single time.
So copy it, run the game now we should
see that all the weapons wrote it around.
There we go without changing
anything and they are still working list-style.
We go rifle, still doesn't get picked
up because we already have the pistol with us.
How cool is that? I hope you enjoyed.
Sorry for coming back.
I know you're already very annoyed.
This is an a step just to save you
maybe a couple of minutes,
hours, whatever it takes you to create animation.
So I hope you enjoy lever of you.
I'll see you in the next one. This time for real.