Camera Euler and Gimbal - Script error

Hello Everybody, I have a Unity5 error when I play and try the camera local rotation, the code is pretty the same still of the video but no works, here the error and the code.

NullReferenceException: Object reference not set to an instance of an object
CameraBehaviour.Update () (at Assets/Scrpits/ShootHoop/CameraBehaviour.cs:21)

using UnityEngine;
using System.Collections;

public class CameraBehaviour : MonoBehaviour {

// Use this for initialization
void Start () {


// Update is called once per frame
void Update () 
	float addRotationSpeed = 3.0f;
	float mouseX = Input.GetAxis("Mouse X") * addRotationSpeed;
	float mouseY = Input.GetAxis("Mouse Y") * addRotationSpeed;
	transform.localRotation = Quaternion.Euler(0, mouseX , 0) * transform.localRotation;
	Camera mainCamera = GetComponentInChildren<Camera>();
	mainCamera.transform.localRotation = Quaternion.Euler(mouseY, 0, 0) * mainCamera.transform.localRotation;


Somebody happens too???
Thanks for the help!

The problem was solved, sorry was my mistake. I drag the script to the “Box Person” and leave it in the scene, and of course, there is no camera component attached.

1 Like

Glad you fixed this Freddy. Generally you should post only discussions here. Question that you need an answer to are best over on Udemy.

Ok Sam, the tutorials are great until now, I keep learning!


I did not assign a float value and straightaway multiplied by 5. It worked still.

float mouseX = Input.GetAxis(“Mouse X”) * 5; // This is what I wrote in my program

Is there something wrong in this because the command is multiplied by 5, hence the rotation speed changes.

Nothing wrong but as a general rule we don’t like unnamed constants hanging around because you will later ask youself: “why did I pick 5?”