Object Reference Error On Camera Script

I am receiving the error:

NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)
CameraColorChange.OnMouseUp () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/Camera/CameraColorChange.js:10)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

With this script:
var thecameras : GameObject;
var color1 : Color;

function OnMouseUp()
	thecameras.camera.backgroundColor = color1;

It points out when I double click on it this section of the script:
thecameras.camera.backgroundColor = color1;

What am I doing wrong here?

The error will be either if thecameras or color1 is set to null. You can use this as a check:


if(thecameras != null && color1 != null)
thecameras.camera.backgroundColor = color1;

I’m not sure which language you’re using, but it may be straightforward to understand.