- Home /
Question by
supertacoman12 · Oct 22, 2014 at 11:40 PM ·
javascriptgameobject
Ai instantiates Game Object but won't stop.
I have an AI script that is supposed to fire a bullet, the problem is that when it starts firing it won't stop. Can someone fix it?
Here is the script.
var Player : Transform;
var laser: GameObject;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
var timer : float = 0;
var timeLimit : float = 10;
private var shooting : boolean = false;
function Start ()
{
//start function
}
function Update ()
{
transform.LookAt(Player);
if(Vector3.Distance(transform.position,Player.position) >= MinDist)
{
transform.position += transform.forward*MoveSpeed*Time.deltaTime;
if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
{
if(!shooting) Fire();
}
}
}
function Fire ()
{
timer+=Time.deltaTime;
if(timer >= timeLimit)
{
Instantiate(laser, transform.position, transform.rotation);
yield WaitForSeconds(3);
shooting = false;
}
}
Comment