- Home /
NullReferenceException: Object reference not set to an instance of an object
I dont get why this script dont works.
function Update () {
if (Input.GetAxis("Mouse ScrollWheel")){
var fov : float = GameObject.Camera.fieldOfView;
GameObject.Camera.fieldOfView=fov+Input.GetAxis("Mouse ScrollWheel");
}
}
Any hints?
The full 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.GetProperty (System.Object target, System.String name) UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name) MouseOrbitifALT.Update () (at Assets/Scripts/Ship/MouseOrbitifALT.js:28)
capitalization is important. GameObject is a class, and gameObject is a GameObject.
you need gameObject.camera, not GameObject.Camera. Fattie is right; you can also go straight to camera.fieldOfView, since gameObject is assumed (in a way). don't forget to tick his answer as correct by clicking the check mark.
Answer by Fattie · Apr 08, 2013 at 02:14 PM
i think it's just
camera.fieldOfView ...
you don't need to mention the gameObject
Also when you post the error, POST THE WHOLE ERROR. The error texts explains what and where you did wrong.
Your answer
Follow this Question
Related Questions
FOV that brings gameObjects close 2 Answers
How to detect an object which be in FOV of certain camera ? 1 Answer
Free Look Camera 1 Answer
Local Multiplayer Camera 0 Answers
How do you reference different cameras 2 Answers