Reload gun script
So I have a issue with my script. I've tried to figure out the math but can't get it. Basically it works great until you have less bullets available than what you're carrying. So if I have 5 shots in the gun and 4 bullets to spare, when I reload, I end up with 10 instead of 9. Any help would be appreciated greatly
public int maxAmmo = 10;
public int currentAmmo;
public float reloadTime = 1.5f;
private bool isReloading = false;
public static int ammoHeld = 20
IEnumerator Reload()
{
isReloading = true;
Debug.Log("Reloading");
yield return new WaitForSeconds(reloadTime);
subAmmo = maxAmmo - currentAmmo;
ammoHeld -= subAmmo;
currentAmmo = maxAmmo;
if(ammoHeld < 0)
{
ammoHeld = 0;
}
isReloading = false;
}
Comment