I have an enemy and a player prefab, the enemy has a player var that it's supposed to move to. It moves to the point in space which the player prefab is at when the game first starts, but it doesn't follow the player. Why is that?
EDIT
Well I'm pretty sure it's not my code, since it works fine when I use it on a regular object that isn't inside a prefab, but here it is.
var Player : Transform;
var elaser : Transform;
var damp = 2;
function Update () {
Player = GameObject.FindWithTag("Player");
if(Vector3.Distance(Player.position,transform.position) < 800){
var rotate = Quaternion.LookRotation(Player.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate,damp * Time.deltaTime);
transform.Translate(0,0, 10 * Time.deltaTime);
}
}
InvokeRepeating("fireAtPlayer",1,2);
function fireAtPlayer() {
if(Vector3.Distance(Player.position,transform.position) < 800){
Instantiate(elaser,transform.Find("espawnpoint").position,transform.rotation);
}
}
function OnCollisionEnter(hit : Collision) {
if(hit.gameObject.tag == ("Player"))
Debug.Log("Watch it!");
}
Also I'm getting Error Message "Using a SerializedProperty after the object has been deleted is not possible. UnityEditor.EditorGUI:SetPrefabOverride(Object, String[], Int32)"