The question is answered, right answer was accepted
I keep getting the error "NullReferenceException: Object reference not set to an instance of an object RobotFollow.Update () (at Assets/Scripts/RobotFollow.js:23)"
For some reason I keep getting this error. Also, the same code I am about to present to you not only pertains to the question Im asking but also to another problem Im having with it. This code is meant for my enemies of the game to follow the main character (Like what a normal enemy would do -persue-). I put the first person controller as the target but they dont move whatsoever when I preview the scene. Please help! Ill supply pictures to describe the second error.
var target : Transform;
var moveSpeed = 3;
var rotationSpeed = 3;
var myTransform : Transform;
function Awake()
{
myTransform = transform;
}
function Start()
{
target = GameObject.FindWithTag("Player").tranform;
}
function Update(){
transform.LookAt(Vector3(target.position.x, transform.position.y, target.position.z));
myTransform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
Answer by whydoidoit · May 12, 2013 at 11:16 PM
So put #pragma strict at the top of your code and you will immediately see the problem - your Start function is getting the target but you've misspelled transform. #pragma strict stops you doing that kind of typo mistake.
Thank you so much! It def. fixed the problem. Ill make sure to incorporate Pragma Strict in all my scripts from now on.
Follow this Question
Related Questions
Enoent error: diskusage.node not found when starting Unity Hub 0 Answers
How to move the Character using WASD 3 Answers
Why is this String.Split() giving a object reference not set error? 1 Answer
[Urgent] Finding Nearest Target 2 Answers
How can I make cam move in a perfect circular orbit, but without diving into colliders? 2 Answers