- Home /
Camera Switcher script
I am having a problem with my script, I am trying to switch to a Rear_cam when the V key is held down and when it is released have it switch back to Main_Camera. When I attempt to use it it gives me this error message:
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) Camswitcher.Update () (at Assets/Scripts/Camswitcher.js:7)
Here is the script I made:
public var Rear_cam :Camera;
public var Main_Camera : Camera;
function Update(){
if (Input.GetKeyDown ("v"))
{
Rear_cam.Camera.enabled = true;
Main_Camera.Camera.enabled = false;
}
if (Input.GetKeyUp ("v"))
{
Rear_cam.Camera.enabled = false;
Main_Camera.Camera.enabled = true;
}
}
Can anyone help me out here? (I'm kind of new to unity)
Answer by Loius · Nov 27, 2012 at 05:46 PM
Capitalization is important in programming. Camera is a class, camera is a member property. It's recommended that you follow Unity's standards of CamelCase for functions and classes, and camelCase for members, to prevent confusion.
Have you assigned a value to your cameras in the inspector?
Your answer
![](https://koobas.hobune.stream/wayback/20220613084602im_/https://answers.unity.com/themes/thub/images/avi.jpg)