Day 38: New collectables!

Objective: create a ammo and health collectable.

We created a ammo system and a health system but what would a game be if you weren’t able to refill your ammo or health? Possibly a hard and not so fun game! We will add power ups that allow us to refill the ammo and health.

We’ll start with the important one, Ammo!

In the player script we will need two new variables. We need to keep track of our current ammo and the max that we want the player to have.

Next will be the create a function that will increase the ammo.

In here we will check to see if the players ammo is not equal to the max ammo. If it is not we will fill the ammo to equal the maxammo amount and update the UI as well. Gotta keep the player informed on the amount they have!

Before moving into the power up script lets add the logic to refill health.

The same way we do damage is how we’ll do the healing but backwards. When the function gets called we need to check to see if it’s not 3 or max health. If it is not equal to 3, we’ll add a live and update the UI. We will need to check to see where the health is at to deactivate the damages, depending on how damaged we are.

Now to move over to the power up script.

We’ll add new cases and call the correct function for each case.

The second to last thing we need to do is create the game objects and assign the correct ID.

We’ll only show the Ammo power up but the Healing one is the same just with it’s ID. Under Rigidbody make sure gravity is set to zero. Turn the objects into prefabs and add to the spawn manager.

That’s how we created two new power ups!

I am passonate on learning to program and use Unity to become a skillful Unity Developer