2D Shooter: Ammo Collectible Part 2

Sabrina Windsor
2 min readAug 19, 2021

--

Objective: Spawn the ammo collectible when the player runs out of ammo and keep spawning every 10 seconds until the player collects it.

Let’s take a look at our player script. We’ll want to communicate with the spawn manager and the ui script, and make a number of bool variables so that we can start and stop certain methods from running at certain times.

Here’s what I have in the update method:

The purpose of _isAmmoSpawning is so that the AmmoDrop will only be initiated once, instead of a multitude of times while the space key is pressed.

Now we want to make sure that when we create the spawning method, that the collectible will stop spawning once its collected. So where we add ammo, we also want to send a message to the SpawnManager that we don’t need another collectible for a while.

And this will make sure the bool in the SpawnManager script is correct.

Now here is the process in the spawn manager that will detect if we need ammo and will spawn a collectible every ten seconds.

And now we should have a working ammo spawn system!

--

--

Sabrina Windsor
Sabrina Windsor

Written by Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!

No responses yet