Galaxy Shooter — Ammo Collectable

How things work initially

The game already possesses a collection of powerups that can be obtained by the player. The scripts for how the powerups are spawned, how they behave after being spawned, and how they behave when they are picked up by the player (or not picked up) are in place initially.

Building the assets

Before anything can be done in Unity, we need to build the sprites that will represent this new powerup. After all, the player needs to know what kind of powerup they just picked up.

The shield powerup sprites/animation
The new ammo powerup

Moving into the scripts

Within the scripts, the main thing we need to do is create the logic for what happens with the player. All of the powerups have some code in the player script detailing what happens with the player when they pick up each type of powerup.

The logic of the ammo powerup
The ammo meter is refilled by the ammo powerup

Making a refinement

Well, we’ve achieved what we set out to do. The ammo powerup spawns properly, and refills the player’s ammo exactly as expected. But much like with the shield update I did in a previous article, the visual feedback seems a little abrupt. Is there a way to make this look smoother?

The ammo powerup logic using a coroutine instead
The ammo meter is refilled in a smoother and more gradual way

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store