ai help: fire shots

I need help fixing the errors in my script please note if you see anything that will go astray from the description of the script.

this script will be attached to a child of the AI. a cube collider is attached to an axis
as a child. it give a firing range to the AI so if i collide with the cube the AI will fire once a second only while you are colliding with the cube. the cube is a trigger so i don’t worry about my bullet colliding with any thing other than the player.

Okay I’ve been having problems with collision lately with more than this. So I may need help with that too. If it helps my player has a character controller. This AI is a rigidbody.

var bulletPrefab:Transform;
var savedTime = 0.0;
var theForce = 1000;

function OnTriggerStay (other : Collider)
{
if(other.gameObject.tag == "Player")
	{
var seconds : int = Time.time;
		var oddeven = (seconds % 2);
		
		if(oddeven)
		{
			Shoot(seconds);
		}		
	}
}			
			function Shoot(seconds)
{
	if(seconds!=savedTime)
	{
	var bullet = Instantiate(bulletPrefab, transform.Find("Firepoint").transform.position,
	Quaternion.identity);
	bullet.rigidbody.AddForce(transform.forward * theForce);
	
	savedTime=seconds;
}

Ok here is what I recommend, use a raytrace to determine if the player is visible to the gun before shooting. Like this:

function TargetVisible () : boolean {
        // Raycast from me to target position
        var hit : RaycastHit;
        if (Physics.Linecast (transform.position, target.position, hit))
             return hit.transform == target;

        // Return false since can't see target
        return false;
}

With this you’ll need to declare a variable for target which would be the player. Then prior to shooting just say:

if (TargetVisible)
     Shoot();