Auto Fire!

Howdy, I have the following script that shoots a “laser” when you hit the space bar, and it works perfectly. I’m trying to change it so the laser shoots automatically every 3 seconds or so, but am not sure where to start. Can anybody give me some pointers?

var laserBeamPrefab : Transform;

function Update ()
{

	if(Input.GetButtonDown("Jump"))
	
	{

		var laserBeam = Instantiate(laserBeamPrefab, gameObject.Find("spawnPoint").transform.position,Quaternion.identity);
    
    	laserBeam.rigidbody.AddForce(Vector3.forward * 100);
			
	}

}

basic timer approach would be something like this:

var lastFireTime : float;
var fireDelay : float = 3.0f;

function Update()
{
	if(Time.time > lastFireTime + fireDelay)
	{
		// fire code in here
		lastFireTime = Time.time;
	}

}

there’s also the InvokeRepeating approach: Unity - Scripting API: MonoBehaviour.InvokeRepeating

Thank you very much. You made it too easy for me :wink: it works perfectly!