I get this error message : NullReferenceException: Object reference not set to an instance of an object PlayerMovementScript.Update () (at Assets/PlayerMovementScript.js:6)
And the code is:
MouseLookScript.js:
#pragma strict
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 lookSmoothDamp : 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, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
}
PlayerMovementScript.js:
var walkAccelaration : float = 5;
var cameraObject : GameObject;
function Update ()
{
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
rigidbody.AddRelativeForce(Input.GetAxis(“Horizontal”) * walkAccelaration, 0, Input.GetAxis(“Vertical”) * walkAccelaration);
}