Thanks in advance.
You can set the vertical field of view easily (though you asked for the horizontal and I know of no simple setter for that).
I think you can set the vertical field of view to derive the horizontal field of view, or you could possibly look into messing with the cameras projection matrix to customize for your needs.
I just had the same problem. Drussilla’s code is a good approximation, but is not exact. This Javascript code should be precise:
var hFOV : float = 30;
function FixedUpdate() {
var hFOVrad : float = hFOV*Mathf.Deg2Rad;
var camH : float = Mathf.Tan(hFOVrad*.5)/camera.aspect;
var vFOVrad : float = Mathf.Atan(camH)*2;
camera.fieldOfView = vFOVrad * Mathf.Rad2Deg;
}
Simply copy the code to a new javascript and attach it to the camera.
To se horizontal field of view for a camera you should create component with following logic:
camera.fieldOfView = 60 * (16f/9f) / ((float)camera.pixelWidth / camera.pixelHeight);
where 60 is your target field of view value.
and 16f/9f - default aspect ration (so the same value for horizontal and vertical field of view give the same image)
Here you can find more information.