Remake gunscript to rapid fire

How do I make this script to rapid fire?

#pragma strict
var bulletPrefab : Transform;
var player : GameObject;
var force : float = 2000;
var shootForce : float = 1000;
 
function Update () {
    if(Input.GetMouseButtonDown(0)){
         fire();
    }
}
 
function fire(){
    var instanceBullet = Instantiate(bulletPrefab,transform.position,Quaternion.identity);
        instanceBullet.rigidbody.AddForce(transform.forward*shootForce);
}



//this works just ask the sphere to this after putting the script to the respwan

Keep track of the amount of time that’s passed while the button is down.

Something like… (I don’t yet know Javascript, apologies if the syntax isn’t quite right.)

var mouseButtonDownTime : float = 0;
var timeBetweenShots : float = .5;

function Update() {
    if (Input.GetMouseButtonDown(0))
    {
        if (mouseButtonDownTime == 0)
            fire();

        mouseButtonDownTime += Time.deltaTime;
        if (mouseButtonDownTime >= timeBetweenShots)
            mouseButtonDownTime = 0;
    }    
}