How do I add ammo and reloads?

My gun is a sci-fi one and in a sense “Reloads itself” but what can I do to add ammo and reloading. I don’t need an animation now just reloading, and what button will it use? I’d like something like… 64 rounds in a clip, and reloading is 3.5 seconds long. Also to make the gun stop firing when ammo = 0. Here’s my script.

#pragma strict
 
var bullet : GameObject;

private var shooting = false;
 
function Start() {
   InvokeRepeating("Shoot", 0.0, 1.0 / bulletsPerSecond);
}
 
function Shoot() {
  if (!shooting) return;
  var go = Instantiate(bullet, transform.position, transform.rotation);
  go.rigidbody.AddRelativeForce(Vector3.forward * 1750.0);
}
 
function Update(){
    shooting = false;
    if(Input.GetAxis("Fire1")){
        shooting = true;
    }
}
private var bulletsPerSecond = 6.0;

Thanks. I’m in Javascript by the way

Reloads are pretty simple. Have 3 more variables, one being the max bullets in the clip, another being the current bullets in the clip and finally the duration of the reload in seconds.

At the start just set the current to the max so you only need to set 1 number and it starts both. Each time you shoot take one off the current number. Only shoot if current number is greater than 1. Now on some other button press use an Invoke function, look up Unity docs how. Call some simple function with it after your reload timer in seconds, in that reload function just set current clip to max clip.

Come to think of it you may need a boolean keeping whether you are reloading or not which you set to true when you press the reload key and false when its done. In the shoot part of the script add another condition that you cant shoot while reloading.

And your done!

Id also recommend not using a background invoke repeating to do your shooting.