NullReferenceException: Object reference not set to an instance of an object (69369)

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.

1 Answer

1

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.

Or Camera.main.fieldOfView

Thanks. That was it.