I'm using a simple enemy ai that makes the enemy follow the player, I am wanting to spawn my enemies one after the other which I have done, but for some reason the enemy only follows the player if both the enemy and the player are in the scene, in other words when I asiign the player as the target in the assets folder when both prefabs are in the assets folder the enemy only moves to the players start potition, is there anyway I can fix this script to accomindate my enemy spawners
var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
function Start ()
{
}
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)
{
//Here Call any function U want Like Shoot at here or something
}
}
}
↧