Hey guys. I'm having a problem with my Enemy AI moving towards my player. It keeps saying "Object reference is not set to an instance of the Object". Think anyone can help me fix it? My code is this;
public class AI1 : MonoBehaviour {
private Vector3 Player;
private Vector2 Playerdirection;
private float Xdif;
private float Ydif;
private float speed;
void start () {
speed = 10;
}
void Update () {
Player = GameObject.FindWithTag("Player").transform.position;
Xdif = Player.x - transform.position.x;
Ydif = Player.y - transform.position.y;
Playerdirection = new Vector2 (Xdif, Ydif);
GetComponent().AddForce(Playerdirection.normalized * speed);
}
}
↧