Why isn't my enemy following my player?

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?


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);



function fireAtPlayer() {
if(Vector3.Distance(Player.position,transform.position) < 800){

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)"

Make sure you put it in the Update function, not the function Awake().

Make sure that the player var is not just the players position. If you have set it to the players position, then try the players transform instead.

And as the comment to your question says. Please provide code :)

If you have multiple objects tagged 'Player', the code won't work (it will choose one of them unpredictably).

If the one object tagged Player isn't actually moving, the code won't work (if for example you're moving the player object's mesh and not its parent, player-tagged object)