Modify Cinemachine Virtual Camera FOV

Modify Cinemachine Virtual Camera FOV

To modify the field of view (FOV) of a Cinemachine Virtual Camera through script, you can use the m_Lens.FieldOfView property of the CinemachineVirtualCamera component. Here is an example of how you can do this in a script:

using UnityEngine;
using Cinemachine;

public class ExampleScript : MonoBehaviour
{
    public CinemachineVirtualCamera virtualCamera;
    public float newFOV = 60;

    void Start()
    {
        // Modify the FOV of the virtual camera
        virtualCamera.m_Lens.FieldOfView = newFOV;
    }
}


In this example, virtualCamera is a reference to the CinemachineVirtualCamera component that you want to modify, and newFOV is a float value that specifies the new FOV. When the script is run, the Start() function will set the FOV of the virtual camera to the specified value.

You can also modify the FOV of a virtual camera at runtime by calling the SetFOV() method of the CinemachineVirtualCamera component. Here is an example of how you can do this:

using UnityEngine;
using Cinemachine;

public class ExampleScript : MonoBehaviour
{
    public CinemachineVirtualCamera virtualCamera;
    public float newFOV = 60;

    void Update()
    {
        // Modify the FOV of the virtual camera
        virtualCamera.SetFOV(newFOV);
    }
}


In this example, the Update() function is called every frame, and the FOV of the virtual camera is set to the specified value. You can call the SetFOV() method at any time to change the FOV of the virtual camera.

I hope this helps! Let me know if you have any questions.