Welcome back, my fellow game developers in this video,
when we run the game are just does not just opened up.
It opens up and gives us in random mapping.
We'll pick it up and we start shooting.
And the best part is that if we keep pressing the Iike,
we don't have more weapons.
You will see why this is such an amazing thing to do.
And a couple of minutes,
so let's not waste any more time.
And let's get started.
K.
So now we have our chest opening.
We actually want to spawn some kind of weapon.
So what we'll do is we're going to
instantiate one of the potential weapons.
Where is it on the weapons just right here.
Now, there is one more thing
that we need to take into consideration,
and that is when we spawn one of these pickups.
It's on the chest immediately and the chest is solid.
So what we're going to do is we're
going to create a spam,
spam, spam spawn point in here.
And we're calling spawn point.
And we'll just move it a little bit down.
And this is where I can just make this bigger.
And this is where the gun is going to
spawn for us and we'll just put it about here.
And if you want, you can also add to each of
these guns the pickup, the D layer.
I think it's a good idea because if
the player is standing right in front of the chest,
we won't even see what the gun was.
So it's a good idea. It's pretty easy.
Just add the script.
We'll maybe do it later on.
But for now, let's keep focused on what we have.
We're go into the weapons just and in here we'll create
an extra serialized field which is of type transform,
and it's going to be the spawn point.
Save that back in Unity,
wait for it to compile and weapons just there we go.
The spot point that now what we're going to
do is in here we want to create a random number,
or at least when we actually press
the key will create a random number.
And from that random number we will
instantiate one of the potential gametes.
So I'm going to issue it to you as a challenge,
so you'll need to spend the weapons pick up.
In here.
We should have pickup.
So you'll need to create a random number.
You'll need to instantiate one of the potential guns.
And you'll need to make sure that it's on
the position of the spawn point.
So with that said,
pause the video right now and go do the challenge.
Okay, welcome back.
So after we change the sprite,
we are going to create an int,
a random weapon, weapon number,
and it's equal to random range.
And the range is from 0 to the potential,
potential weapons dot length.
And in here we are going to go ahead and instantiate.
Instantiate opens up what is the object?
It's going to be the potential weapons on the position,
random weapon number,
the spam point dot position and the spam point 0, 0, 1.
Save that.
And now let's go back and to our game.
I believe this is all that we need to do.
Okay, Let's go back.
Let's make this a bit bigger.
Run the game.
Stand next to the chest, hit the Iike.
There we go. How cool is that?
Now we have the shotgun,
we can actually pick it up and start shooting.
Now, there is one more thing
that we need to take into consideration.
And then I can spawn as money,
weapons as I want,
is something that you might think is good.
But in actuality, it's not.
Maybe you do want to have this, maybe you don't.
And I'm going to give you
an opportunity to do this on your own.
Pause the video if you want.
This is not an official challenge.
I'll give you a couple of seconds.
Pause the video, figure out how we can stop this.
O K time's up.
So in here I'm going to add a,
another Boolean which is the has been open.
It opened, opened. And in here,
after we actually open the chest,
the has been opened equals true.
And another condition in here,
if it has not been opened,
save that, and I want to add it to one other place.
And it's in here where we set the Vicky back to true.
So in here I'm going to say,
excuse me, that's a lot.
If it has not been opened,
then we are going to turn this on.
Save that.
And if we're out,
then we'll just set it to false and
will never open an account.
So we don't want to keep seeing the text
when we have already opened that chest.
So we run the game.
We have the chest.
We open it up.
We have the shotgun who tried to open up another time.
No, we cannot if we go back, that's it.
We don't see it because we've already opened
and we pick up our app and we shoot around.
We have an amazing weapons spawning,
chest opening, picking up
mechanic that works perfectly fine.
So I hope you enjoy it.
And if you want to have some extra challenge on the side,
maybe create some kind of animation for the chest where
it may be wobbles left and right before it opens up.
Or I don't know, maybe add some kind of
extra animation if you have
for the chest to find on yourself.
With that done, make sure to always commit
your changes if you haven't already, you know the drill.
I it helps me out a
lot when you leave a review positive 1,
of course, a review on the course Atlas, the platform.
Know that I am the author of
this course is worth watching,
worth showing to other people
and joined the discord obviously,
if you haven't already,
and I hope you enjoyed this section.
It was really nice. We learned a lot.
And the next one, I'm not sure what we're going to do,
but I'm sure we will figure it out by them.
So let's not waste any more time and
let's go to the next section.