Hi all, I’m currently working on a rogue-like, top-down 2d shooter game, but I am having trouble with the cooldown mechanism. So far, the player has three ammo that will take 2 seconds to reload once depleting. But, I’ve noticed that if you spam during the cooldown, many projectiles will suddenly be instantiated after reloading and these do not affect the ammo count at all. Here’s my player script:
void Update()
{
//INPUT
ProcessInputs();
//SHOOTING
Shoot();
//UPDATING AMMO TEXT
ammoText.text += " " + ammo.ToString();
}
void Shoot()
{
if (Input.GetKeyDown(KeyCode.Mouse0) && ammo > 0)
{
Instantiate(butterProjectile, transform);
ammo--;
}
else if (ammo == 0)
{
StartCoroutine(Reload());
}
}
IEnumerator Reload()
{
//RELOAD COOLDOWN
yield return new WaitForSeconds(2f);
//BACK TO FULL AMMO :D
ammo = 3;
}
(Sorry I know it’s pretty basic code.) I doubt this has anything to do with the projectile script, but I can’t seem to find anything wrong in this one. Any help would be most appreciated. Thank you ![]()
Edit: This issue also occurs after reloading and the ammo count goes all wild when I start spamming my mouse ![]()