How to change this script from single shot to automatic shooting?

Hello, this is my first post so sorry if I don’t do it right :smile:, but anyway, I had a question how i could change this shooting script to make it were instead of clicking multiple times to shoot I could just hold down the left click button and rapid fire? Here is the Script…

public var bulletPrefab : Transform;
public var bulletSpeed : float = 6000;
var ammo : int = 60;
var gunShot : AudioClip;
var reload : AudioClip;
var emptyClip : boolean = false;

function Update () {
if(Input.GetButtonDown(“Fire1”)) {
if(ammo > 0) {
Shoot();
}
else{
return;
}
}
if(Input.GetKeyDown(KeyCode.R)) {
if(emptyClip) {
Reload();
}
}
if(ammo >= 0) {
emptyClip = true;
}
else {
emptyClip = false;
}
}

function Shoot(){
var bullet = Instantiate(bulletPrefab, transform.Find(“BulletSpawn”).position, transform.Find(“BulletSpawn”).rotation);
bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
audio.PlayOneShot(gunShot);
ammo–;
}

function Reload() {
audio.PlayOneShot(reload);
ammo = 60;
}

function OnGUI() {
GUI.Label(Rect ( 0,0, 75, 25), "Ammo " + ammo);
}

Thanks! Bye.

You’ll want to use GetButton() instead of GetButtonDown() - GetButtonDown only returns true for a single frame, GetButton will return true as long as the button is down. Take a look at the example in the GetButton link, since you’ll also want to implement some kind of timing to control the fire rate.

Also, please use Code Tags when posting code on the forums.