Script: var target : Transform; var moveSpeed = 3; var rotationSpeed = 3; var myTransform : Transform; function Awake() { myTransform = transform; } function Start() { target = GameObject.FindWithTag("Player").transform; } function Update(){ transform.LookAt(Vector3(target.position.x, transform.position.y, target.position.z)); myTransform.Translate(Vector3.foward * moveSpeed * Time.deltaTime); } This is my error: NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) AIFollow.Update () (at Assets/AIFollow.js:19) What am I failing to assign?
Have you checked if your object has the tag "Player"? If yes, is it active/enabled? If no to any of the two questions, GameObject.FindWithTag("Player") will return null. Thus, you get the error when you use target in the Update() function.
I closed Unity and opened back up and the error was gone...Strange. Thank everyone for their suggestions. Now I know what to look for if problem arises in future.