I am writing a movement script using CharacterController. I have a characterController component attached to my object, but, it keeps returning a NullReferenceException. I have tried creating a new object as well as importing one of the example objects, but nothing seems to work. Below is all the code in the script that mentions the CharacterController.
private var character : CharacterController;
character = GetComponent(CharacterController);
if(this.transform.position != standardPos)
var target : Vector3 = standardPos;
target.y = transform.position.y; // keep waypoint at character's height
var moveDirection : Vector3 = target - transform.position;
if(moveDirection.magnitude < 1)
transform.position = target; // force character to waypoint position
Is this all located in Update?
Wow, herp derp :P thanks :P
I made that an answer so you can accept it and this question can be forever closed :)
Answer by Benproductions1
Jun 01, 2013 at 08:24 AM
Place that code in the Update function and it will work :)
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
15 People are following this question.
The name 'Joystick' does not denote a valid type ('not found')
Character Controller moves forever after colliding with object
Character Controller problem
Problem with Movement Script
Let Character Controller jump.