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 post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
15 People are following this question.
The name 'Joystick' does not denote a valid type ('not found')
How do I fix my player jumping code?
Character Controller Rotation