ammo count

can anyone build off my script of give me an idea or tutorial on how to count ammo. Here is my script. (it a js.)


var bullet : Rigidbody;
var speed = 50;

function Update () 
{
    if(Input.GetButtonDown("Fire2"))
    {
        var clonedBullet : Rigidbody = Instantiate(bullet, transform.position, transform.rotation);
        clonedBullet.velocity = transform.TransformDirection(Vector3(0,0,speed));
    }
}

var bullet: Rigidbody;
var speed = 50;
var AMMO = 10;

function Update()
{
    if(Input.GetButtonDown("Fire2"))
    {
        if(AMMO > 0)
        {
            var clonedBullet : Rigidbody = Instantiate(bullet,transform.position,transform.rotation);
            clonedBullet.velocity = transform.TransformDirection(Vector3(0,0,speed));
            AMMO --;
        } // You forgot that one
        else{
            print("NOAMMO");
        }
    } // And those two
}

this Checks if it has ammo otherwise it wont shoot at all.