Gun Ammo Help

Ok my problem with my script is thats it has a total of 30 bullets, if i shoot 16 bullets and press r i will still have 14 left. reloading only works if i have no bullets left. Can you tell me how to make it so every time i press r i have 30 bullets to shoot. Heres script…

var prefabBullet:Transform;
var shootForce:float;
var shots : int = 0;
var maxShots : int = 30;
var shootSound : AudioClip;
function Update()
{
    if(Input.GetButtonDown("Fire1") && shots < maxShots)
    {
        var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
        instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
        audio.PlayOneShot(shootSound);
        shots++;
    }
    else if (shots >= maxShots && Input.GetKeyDown(KeyCode.R))
    {
        shots = 0;
    }
}

Take out the “else” on the second if statement and it will work.

What you put was var shots : int = 0; right well if you change the 0 to 14 then it will reload at 14 bullets. Here is an example var shots : int = 14; Hope it was useful.

Just change the “>” for “<” . Changing that you can reload every time you want.

var prefabBullet:Transform;
var shootForce:float;
var shots : int = 0;
var maxShots : int = 30;
var shootSound : AudioClip;
function Update()
{
    if(Input.GetMouseButtonUp(0) && shots < maxShots)
    {
        var instanceBullet = Instantiate(prefabBullet, transform.position, Quaternion.identity);
        instanceBullet.rigidbody.AddForce(transform.forward * shootForce);
        audio.PlayOneShot(shootSound);
        shots++;
    }
    else if (shots <= maxShots && Input.GetKeyDown(KeyCode.R))
    {
        shots = 0;
    }
}