continuous shooting

i am making a space shooter game. i am looking for a way to make a while script that detects when the mouse 1 or “Fire1” input is down. but i don’t want to have the bullets be instantiate every frame in the update. how would i make it so the bullets shot out only once every half a second or so while the input is there? any other suggestions. thank you

Use InvokeRepeating and CancelInvoke, along with GetButtonDown and GetButtonUp:

var fireRate = .5;

function Update () {
	if (Input.GetButtonDown("Fire")) {
		InvokeRepeating("Shoot", .001, fireRate);
	}
	else if (Input.GetButtonUp("Fire")) {
		CancelInvoke("Shoot");
	}
}

function Shoot () {
	// do shooty stuff here
}