I am making a zombie shooter and I’m having an issue where when i reload and per say i have a total of 5 bullets left, the clip size is 8 when i reload it will reload 8 bullets setting the total bullets remaining to -3 how can i make my script so it will never pass 0, and if there was say 2-3 bullets left in the stockpile, that when i reload it will only load those 2-3 bullets not a full clip.
Some coding to show where i am at…
if (reloading)
{
canShoot = false;
reloadTimer -= Time.deltaTime;
if(reloadTimer <= 0)
{
ammoClip -= origClip;
ammoClip += spareBullets;
bulletClip = origClip;
spareBullets = 0;
reloading = false;
canShoot = true;
reloadTimer = startRTimer;
}
}
public void reload()
{
if (ammoClip >= 0)
{
spareBullets = bulletClip;
aud.PlayOneShot(reloadSound);
canShoot = false;
reloading = true;
anim.Play("APCReload");
}
}
Let me explain… spareBullets is say the clip holds 8 bullets, i shoot 5 and reload, it would have destroyed those 3 unused bullets, but spareBullets takes that number of bullets left in a clip while reloading and adds them to the stockpile…
ammoClip is total bullets.
bulletClip is currently loaded into the gun.
origClip is a memory to how many bullets will fit into a clip.