Change Camera.VerticalToHorizontalFieldOfView by script?
I am testing a game with 3 projectors(multi monitor) with a final screen resolution 5760 x 1080. I want to change by code Camera>Fov Axis but I can't figure how, I got this error: "Member 'Camera.VerticalToHorizontalFieldOfView(float, float)' cannot be accessed with an instance reference; qualify it with a type name instead". I have tried this codes: `
[SerializeField] Camera[] cams3;
void Update()
{
if (Input.GetKeyDown(KeyCode.End))
{
ChangeFovAxis();
}
}
void ChangeFovAxis() {
var cam = Camera.main;
cam.VerticalToHorizontalFieldOfView(1, 1); // doesn't work same error from the loop below
for (var i = 0; i < cams3.Length; i++)
{
cams3[i].VerticalToHorizontalFieldOfView(90, 1); // I need to change the 3 cams
}
Camera.VerticalToHorizontalFieldOfView(90, 1); // no error but nothing happens
}
Answer by mojer_unity · Jan 07 at 09:57 AM
Hi, If you want to change the field of view of your camera, you should do it like that:
your_camera.fieldOfView = desired_value;
VerticalToHorizontalFieldOfView is just a function that returns an horizontal FOV from a vertical FOV and an aspect ratio. And it should be called always from the class name,not from an instance.
Tks for the replay. Could you show a sample code how to call it? My main intention is to test on multimonitor( 5760 x 1080 -3 cams) if is better FOV Axis vertical or horizontal, which one has less distortion.