How to change a fieldofview in Unity3d 5
use the codes in 4.3 will show
An object reference is required to access non-static member `UnityEngine.Camera.fieldOfView'
So how to fix it and how to get/set field of view, thanks
Answer by pako · Sep 27, 2015 at 02:32 PM
Here's how to set the fieldOfView of the Main Camera (tagged "MainCamera"):
public void ChangeFieldOfView(float degrees)
{
Camera.main.fieldOfView = degrees;
}
Call the ChangeFieldOfView method and pass the new fieldOfView as an argument. Of course, you can just use anywhere in your code:
Camera.main.fieldOfView = 30f; // to set FOV to 30 degrees for example
If you don't want to set the FOV for the main camera, please provide some details about which camera you want to do this. But generally, you must have a reference to the particular camera.
Yeah, I use it, this is the code:
if(Camera.orthographic){
Camera.main.orthographicSize+=delta$$anonymous$$agnitudeDiff*orthoZoomSpeed;
Camera.main.orthographicSize=$$anonymous$$athf.$$anonymous$$ax(Camera.orthographicSize,0.1f);
}else{
Camera.main.fieldOfView+=delta$$anonymous$$agnitudeDiff*orthoZoomSpeed;
Camera.main.fieldOfView=$$anonymous$$athf.Clamp(Camera.fieldOfView,0.1f,179.9f);
}
but there is somwthing wrong, and get
An object reference is required to access non-static member `UnityEngine.Camera.fieldOfView'
You are getting this error because you are not referencing a specific instance of the Camera. Try this:
if(Camera.main.orthographic){
Camera.main.orthographicSize+=delta$$anonymous$$agnitudeDiff*orthoZoomSpeed;
Camera.main.orthographicSize=$$anonymous$$athf.$$anonymous$$ax(Camera.main.orthographicSize,0.1f);
}else{
Camera.main.fieldOfView+=delta$$anonymous$$agnitudeDiff*orthoZoomSpeed;
Camera.main.fieldOfView=$$anonymous$$athf.Clamp(Camera.main.fieldOfView,0.1f,179.9f);
}
Your answer
Follow this Question
Related Questions
Changing Camera Field of View 0 Answers
Camera Field of View 2 Answers
How can I find the magnification multipler from FOV? 0 Answers
I can't fit a plane to my field of view 2 Answers