Altered Turret Script Not Working

Maybe you guys can help, but I have no idea…
Both scripts are attached to a sphere which pivots correctly towards the target, fires correctly, and auto-adjusts correctly. However, I just want it to shoot one bullet every so often. Currently, it fires constantly (until it needs to re-adjust).

SentryGun.js:

var attackRange = 30.0;
var shootAngleDistance = 10.0;
var target : Transform;
var timer = 0.5;

function Start () {
	if (target == null  GameObject.FindWithTag("Player"))
		target = GameObject.FindWithTag("Player").transform;
}

function Update () {
	if (target == null)
		return;
	
	if (!CanSeeTarget ())
		return;
	
	// Rotate towards target	
	var targetPoint = target.position;
	var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
	transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 4.0);

	// If we are almost rotated towards target - fire one clip of ammo
	var forward = transform.TransformDirection(Vector3.forward);
	var targetDir = target.position - transform.position;
	if (Vector3.Angle(forward, targetDir) < shootAngleDistance)
		SendMessage("Fire");
}

function CanSeeTarget () : boolean
{
	if (Vector3.Distance(transform.position, target.position) > attackRange)
		return false;
		
	var hit : RaycastHit;
	if (Physics.Linecast (transform.position, target.position, hit))
		return hit.transform == target;

	return false;
}

MachineGun.js:

var range = 100.0;
var timer = 0.5;
var missile : GameObject;

function Fire () {
	yield new WaitForSeconds (timer);
	var position : Vector3 = new Vector3(0, 0, 0) * 1.0;
	position = transform.TransformPoint (position);
	var thisMissile : GameObject = Instantiate (missile, position, transform.rotation) as GameObject;
	Physics.IgnoreCollision(thisMissile.collider, collider);
}

BulletForce.js (attached to the bullet):

var explosion : GameObject;
var LevelDeath : int = 0;
var Speed : int = 1000.0;

function FixedUpdate () {
	rigidbody.AddForce (transform.TransformDirection (Vector3.forward) * Speed);
}

function OnCollisionEnter(collision : Collision) {
	var contact : ContactPoint = collision.contacts[0];
	
	if (collision.gameObject.tag == "Player")
	{
		Destroy (gameObject);
		Destroy (collision.gameObject);
	}
	
	if (collision.gameObject.tag == "Wall")
	{
		Destroy (gameObject);
	}
	if (collision.gameObject.tag == "Destructable")
	{
		Destroy (collision.gameObject);
		Destroy (gameObject);
	}
}
 if (Vector3.Angle(forward, targetDir) < shootAngleDistance) 
      SendMessage("Fire");

You’re executing your fire routine as fast as Update() can spit them out.

Okay, I’ve changed that too:

 if (Vector3.Angle(forward, targetDir) < shootAngleDistance) 
      SendMessage("FireTimer");

And added this:

function FireTimer(){
	yield WaitForSeconds (firetimer);
	SendMessage("Fire");
}

But I still get the same result. The bullets just spray out like crazy every frame.

Okay, I figured it out. I dove into the FPS tutorial’s code a little more and got a better understanding of just how it worked. Here’s my final MachineGun.js (all the other scripts are the same):

var range = 100.0;
var fireRate = 0.05;
var timer = 1;
var missile : GameObject;

private var nextFireTime = 0.0;
private var m_LastFrameShot = -1;

function Fire () {
	if (Time.time - fireRate > nextFireTime)
		nextFireTime = Time.time - Time.deltaTime;

	while( nextFireTime < Time.time) {
		FireOneShot();
		nextFireTime += fireRate;
	}
}

function FireOneShot (){
	var position : Vector3 = new Vector3(0, 0, 0) * 1.0;
	position = transform.TransformPoint (position);
	var thisMissile : GameObject = Instantiate (missile, position, transform.rotation) as GameObject;
	Physics.IgnoreCollision(thisMissile.collider, collider);
	m_LastFrameShot = Time.frameCount;
}