- Home /
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; color1[0]; color1[1]; color1[2]; color1[3];
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?
I really dont see any errors i have, and i only get errors when running the script, not compiling it.
Answer by Firedan1176 · Feb 14, 2015 at 10:49 PM
The error will be either if thecameras
or color1
is set to null
. You can use this as a check:
C#
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.
i have tried this and no it gives me the same error
for real confused here, i know its checking null, but its saying the reference is not set to an instance of an object, yet if i just use one object which i know for sure has a camera, it has the same error on run