New AI simple problem

In my AI code the enemy need to move around and shot,that’s my code:

var speed: float=20;
var rotateSpeed:float=50;
var direction:int=1;
var speed_rock = 150.0;

function FireRocket () 
{
	 yield WaitForSeconds(2);
	var bullet = GameObject.CreatePrimitive(PrimitiveType.Cube);
        bullet.AddComponent(Rigidbody);
	bullet.transform.position = transform.position;
	bullet.transform.rotation= transform.rotation;
bullet.rigidbody.velocity = transform.forward * speed_rock * -1;
	bullet.rigidbody.mass = 3;
   }

function Update()
{
derection=Random.Range(-1,1);
if(!Physics.Raycast(transform.position,transform.forward,5))
{
transform.Translate(Vector3.forward*speed*Time.smoothDeltaTime);
}
else
{
transform.Rotate(Vector3.up,90*rotateSpeed*Time.smoothDeltaTime*direction);
}
FireRocket ();
}

When I test it out the enemy shots like a crazy:shock:.How can i make a time control to the shot?(one shot per time)

Don’t call FireRocket() every Update(). Either throttle calls to FireRocket() or, since you fire constantly, make FireRocket loop (wrap the body of the function in “while (true) { … }” for example) and call it just once from Start() or OnEnabled().