I have been trying to make an enemy script that cause the enemy to move towards the player. As far as i know i’m accessing the player object properly but my position variable always returns 0,0 which i suspect is null. My enemy object always moves towards 0,0,0 below is my script please could you have a look and see what i’m doing wrong? I’m new so please try and explain why I’m wrong as well but if you don’t have the time, thanks anyway ![]()
PS: My player object does have the tag “Player” on top level and has a transform attached
using UnityEngine;
using System.Collections;
public class enemyControllerA : MonoBehaviour {
public GameObject target;
public float speed;
Vector2 playerPos;
void Start () {
target = GameObject.FindWithTag ("Player");
}
// Update is called once per frame
void Update () {
playerPos = new Vector2(target.transform.position.x,target.transform.position.y);
float step = speed * Time.deltaTime;
transform.position = Vector2.MoveTowards (transform.position,playerPos,step);
print (playerPos);//always returns 0,0?? why god why!!!!
}
}

Read just above my code
– Anthonyknowles