- Home /
Rigidbody Problem - Object reference not set
Hey guys, I have a little problem with my script where I cannot move the GameObject/Player because of the following error:
NullReferenceException: Object reference not set to an instance of an object
PlayerMovement.Update () (at Assets/Scripts/Character/PlayerMovement.js:14)
The problem only shows when the I am running the game, the problem is happening because I am using Unity 4 and the tutorial is an older version. This is the script I have written:
#pragma strict
var WalkAcceleration : float = 5;
var CameraObject : GameObject;
function Start ()
{
}
function Update ()
{
//Rotation Y was made public in MouseLook script
transform.rotation = Quaternion.Euler(0, CameraObject.GetComponent(MouseLook).rotationY, 0);
rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * WalkAcceleration, 0, Input.GetAxis("Vertical") * WalkAcceleration);
}
Thanks for the help guys, really means a lot.
Did you remember to drag the camera object to CameraObject in the inspector?
Yeah, I have done that already, still can't figure it out :(
Thanks for all the help guys, I have sorted the problem out. I made an error in my $$anonymous$$ouseLook Script and BenProductions you was right :), thanks buddy
Answer by Benproductions1 · Jul 25, 2013 at 11:01 PM
Does you camera have a MouseLook
script attached?
Your answer
Follow this Question
Related Questions
How to access the light component on a camera object? 1 Answer
Converted MouseLook from C# to Java problems 2 Answers
Camera Movement (One Position to Another) 1 Answer
Screen Position Out of view frustum error while zooming in gun 0 Answers
Switching Cameras - Confusion with Two Code Samples 2 Answers