Automatic rigidbody gun

Hi again!

I have a shoot java script that shoots a single Rigidbody at a time. is there a way to place an automatic function for
the harpoon script like a machinegun? if so, how do i do it?

this is my script:

var throwSound : AudioClip;
var harpoonObject : Rigidbody;
var throwForce : float;
var endTime : float;
var hitParticles : ParticleEmitter;

private var canShoot : boolean = true;
private var startTime = 0;

function Update () {

if(Input.GetButtonDown(“Fire1”) canShoot) {
//audio.PlayOneShot();
canShoot = false;
startTime = Time.time;
var newHarpoon : Rigidbody = Instantiate(harpoonObject, transform.position, transform.rotation);
newHarpoon.name = “harpoon”;
newHarpoon.rigidbody.velocity = transform.TransformDirection(Vector3(0,throwForce,0));
Physics.IgnoreCollision(transform.root.collider, newHarpoon.collider, true);
}

if((Time.time - startTime) > endTime) {
canShoot = true;
}
}

@script RequireComponent(AudioSource)

change this
if(Input.GetButtonDown(“Fire1”) canShoot) {
//audio.PlayOneShot();
canShoot = false;

to
untilNextShot -= Time.deltaTime;
if(Input.GetButton(“Fire1”) untilNextShot <= 0 canShoot) {
//audio.PlayOneShot();
untilNextShot = TimeBetweenShots;

then add these among the variables;
var TimeBetweenShots : float;
private var untilNextShot : float;

Then in your inspector “Time Between Shots” will appear. The main principle is that you change GetButtonDown (when it’s pressed) to just GetButton (when it is held down) and added some sort of cooldown variable so if the mouse button is held down it will shoot every (TimeBetweenShots) seconds.

I hope it helped you.

(I hope it’s error-free as I never use nor have used JavaScript).

this works perfectly! thanx!

is there a way to modify the script so it can shoot by itself?