Repeating Function on holding down a mousebutton

This is a shooting script, but I want that if I hold the mousebutton down, it keeps firing bullets. Like an automatic weapon.

var projectile : Rigidbody;

var speed = 100; var fireRate = 100;

function Update() { InvokeRepeating("Fire",0.1,0.1); }

function Fire() { if( Input.GetButtonDown( "Fire1" ) ) {

    var instantiatedProjectile : Rigidbody = Instantiate(

projectile, transform.position, transform.rotation );

    instantiatedProjectile.velocity =

transform.TransformDirection( Vector3( 0, 3, speed ) );

    Physics.IgnoreCollision( instantiatedProjectile. collider,

transform.root.collider ); CancelInvoke();

}

}

Thanks

Change GetButtonDown to GetButton. If you want to time it (rather than use InvokeRepaeting, do the following:

var savedTime: float = 0.0;

function Fire(){
    if ((Time.time-savedTime) > (1/fireRate)){
        savedTime = Time.time;
        // shoot
    }
}