- Home /
NullReferenceException:"Object reference not set to an instance object"
Hello everyone, I´m new in unity 3d so I was making a very very fps(Thanks to ETeeskiTutorials). So I attach a "MouseLookScript" to the main camera and It´s work. Well, then I create a capsule and I use it as "PlayerCapsule". Next I Attach the main camera to the PlayerCapsule so the main camera follow the "player". Well, when i want to test the "game"xD Its says NullReferenceException:"Object reference not set to an instance object"
I dont know what is happening, here i give us the scripts that i use:
MouseLookScript:
var LookSensitivity : float = 5;
@HideInInspector
var yRotation : float;
@HideInInspector
var xRotation : float;
@HideInInspector
var currentYRotation : float;
@HideInInspector
var currentXRotation : float;
@HideInInspector
var yRotationV : float;
@HideInInspector
var xRotationV : float;
var LookSmoothDump : float = 0.1;
function Update ()
{
yRotation += Input.GetAxis("Mouse X") * LookSensitivity;
xRotation -= Input.GetAxis("Mouse Y") * LookSensitivity;
xRotation = Mathf.Clamp(xRotation, -90, 90);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, LookSmoothDump);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, LookSmoothDump);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}
PlayerMovementScript:
var walkAcceleration : float = 5;
var cameraObject : GameObject;
function Update ()
{
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentyRotation, 0);
rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration, 0, Input.GetAxis("Vertical") * walkAcceleration);
}
Which line of code does the error happen on? The Unity editor should tell you this. We need to know too in order to help.
I fix it, thanks to cagezero, but i have another problem, its says Input Axis X is not setup, i know i have to go to edit, project settings, input but i dont know how to set up, and also i thinks Axis Y is not set up, thanks for reading
You should mark cagezero's answer as accepted then. And if you hvae a new question you should post a new question.
Answer by cagezero · Dec 19, 2012 at 09:11 PM
Change:
transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLookScript).currentyRotation, 0);
To:
transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
Your answer
Follow this Question
Related Questions
Object reference not working 0 Answers
Object Refererence not set yada yada... 2 Answers
Object reference not set to an instance of an object. 0 Answers
NullReferenceException was thrown. Object reference not set to an instance of an object. 1 Answer
Object reference not set to an instance of an object 0 Answers