- Home /
NullReferenceException
I am making a third person controller. My script is as follows-
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
I am getting the error -
NullReferenceException: Object reference not set to an instance of an object move around.Update () (at Assets/move around.js:14)
Answer by Bovine · Jul 23, 2012 at 04:47 PM
Hard to say without seeing what the line numbers are but I would imagine your controller is null - is the CharacterController attached to the same GameObject as this script?
-----" is the CharacterController attached to the same GameObject as this script?" Thank you So much for the answer it realy helped me.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Instantiate giving a NullReferenceError 1 Answer
C# Textfield Null Reference Exception 1 Answer
C# Need Help Finding Where Null Reference Exception Is 2 Answers