Is this a good way to add zoom in/zoom out?

Hi,

I added a zoom in/zoom out feature to my cinemachine using a combination of different post/articles:

public class FollowCamera : MonoBehaviour
{
    private CinemachineComponentBase componentBase;
    private new CinemachineFramingTransposer camera;

    [SerializeField] float maxCameraDistance = 12f;
    [SerializeField] float minCameraDistance = 1f;

    private void Start()
    {
        componentBase = GetComponent<CinemachineVirtualCamera>().GetCinemachineComponent(CinemachineCore.Stage.Body);
        camera = (componentBase as CinemachineFramingTransposer);
    }

    // Update is called once per frame
    void LateUpdate()
    {
        if(Input.mouseScrollDelta.y < 0f && camera.m_CameraDistance < maxCameraDistance)
        {
            camera.m_CameraDistance++;
        }
        else if (Input.mouseScrollDelta.y > 0f && camera.m_CameraDistance > minCameraDistance)
        {
            camera.m_CameraDistance--;
        }
    }
}

Is this a good way to implement this? Results look like this:
ezgif-2-9b077e0aed

Privacy & Terms