Hold Button Shooting

I need to make it so that when you hold down “Fire1” the player shoots continuously until you release. Is there a way to do that? Here’s the script I’m using to shoot:

var Laser : GameObject;

function Update () 
{
	if(Input.GetButtonDown("Fire1"))
	{
		Instantiate(Laser, transform.position, transform.rotation);
	}
}

The script works but all I need is to make shoot continuously when holding a button down. Please help.

Input.GetButton is what you're after. It's used the same as you have in your code above, but is activated for all frames the button is held down.

you need to create a “fireSpeed” variable, so var fireSpeed = .5 will make them fire every half a second. then all you need is in your if statement,

if(Input.GetButton(“Fire1”) && Time.time > firespeed)

what that does is compares the current time passed to your firespeed. I believe that’s what you’re looking for.

create a fire rate then check how much time has pass using

public float firerate = 1f;
public float canfire= 1f;
if(input.GetButton(“Fire1”) && Time.time > canfire){
canfire
shoot();
canfire = Time.time + firerate;

}