Limited Ammo Script

I was wondering how i would make a limited ammo script for a shotgun. I’m Using the script from tornado twins for simplicity, so how would i add a counter that counts how many times a prefab is spawned(My Bullet) and makes it “reload” after every shot? there would have to be a delay between each shot…

var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab:Transform;

function Update ()

{

	var controller : CharacterController = GetComponent(CharacterController);

	
	// Move? forward / backward
	var forward = transform.TransformDirection(Vector3.forward);
	var curSpeed = speed * Input.GetAxis ("Vertical");
	
	if(Input.GetButtonDown("Fire1"))
	
		{
		var bullit = Instantiate(bullitPrefab, GameObject.Find("SpawnPoint").transform.position,Quaternion.identity);
	
				bullit.rigidbody.AddForce(transform.forward * 3500);
		}


}

@script RequireComponent(CharacterController)
var speed = 3.0; 
var rotateSpeed = 3.0; 
var bullitPrefab:Transform;
var currentBullets = 0;//This is the amount RIGHT NOW that the gun has. (should be 0 by default.)
var totalBullets = 5; //TOTAL amount the gun will have

function Update () 

{ 

   var controller : CharacterController = GetComponent(CharacterController); 

    
   // Move? forward / backward 
   var forward = transform.TransformDirection(Vector3.forward); 
   var curSpeed = speed * Input.GetAxis ("Vertical"); 
    
   if(Input.GetButtonDown("Fire1")) 
    
      { 
if (currentBullets > 0) //only shoot if you have ammo.
{
      var bullit = Instantiate(bullitPrefab, GameObject.Find("SpawnPoint").transform.position,Quaternion.identity);
    
            bullit.rigidbody.AddForce(transform.forward * 3500); 

currentBullets--; //subtract one
}
else //if you have less than 1 bullet
{
//perform reload animation
 currentBullets = totalBullets; //reset ammo count
}

      } 

} 

@script RequireComponent(CharacterController)

I typed this up in this editor so it may have a few typos.

You should get the idea though.

var speed = 10;//speed of bullet
var ammo:Rigidbody;//ammo
var currentBullets = 0;//This is the amount RIGHT NOW that the gun has. (should be 0 by default.)
var totalBullets = 30; //TOTAL amount the gun will have
var readynow : boolean = true;

animation[“uzi reload”].wrapMode = WrapMode.Clamp;//your reload animation’s name

animation.Stop();

function Update ()

{
if(Input.GetButton(“Fire1”))
{
if (currentBullets > 0) //only shoot if you have ammo.
{
readynow = false;//can’t shoot
var ammoClone : Rigidbody = Instantiate(ammo, transform.position, transform.rotation);
ammoClone.velocity = transform.forward * speed;
yield WaitForSeconds(.1);// pause between shots
readynow = true;//can shoot

currentBullets–; //subtract one
}
else //if you have less than 1 bullet
{
//perform reload animation
readynow = false;//can’t shoot
animation.CrossFade(“uzi reload”);
currentBullets = totalBullets; //reset ammo count
yield WaitForSeconds(2);//however long your reload animation is
readynow = true;// animation over can shoot
}

}

}
function LateUpdate ()
{
if(readynow)
{
Update();
}
}

None of youre codes work i keep geting errors