Ammo Drops: Reloading in Space (Game Dev Day 36)
Objective: Provide a powerup drop that will give the player more ammo.
Last time, we created an ammo system to limit the player’s ability to spam projectiles. However, there is no method for the play to gain more ammo currently. They get 15 shots and then the game is essentially over. Let’s add a pickup that will give them 15 more shots.
First, either find or make the sprite you want to use for the pickup. It can just be a placeholder cube or text if you do not have the visual you want. Attach the PowerupScript to this object by dragging the script onto it in the Hierarchy.
MAKE SURE YOU MAKE THIS OBJECT A PREFAB
Next, let’s add it to the Powerup Script’s array as case 3
On our player script, let’s create the GetAmmo function:
This will add 15 to our ammo, and then tells the UI manager to update the player’s Heads Up Display (HUD) to reflect their new ammo count.
Next, in Unity we need to add this powerup to the Spawn Manager item so that it can be spawned during gameplay. We will need to add a new element and drag the Ammo_Powerup Gameobject into the appropriate slot.
Lastly, on the SpawnManager’s script ensure the range encompasses the Ammo_Powerup (this is our fourth powerup).
Now let’s test it in game.
As always, feel free to play with numbers. If you want the ammo pickup to give you 100 ammo, its your game. Seeing as it has a 25% chance to spawn every 7 seconds, I am keeping mine at 15 for now.