Scrollwheel Step Zooming Camera in Adventure Viewtype

Vyn Halcyon

New member
Hi!

This is basically what I want to do:

C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraScrollWheelZoom : MonoBehaviour
{
    public Camera selectedCamera;
    
    private void Awake()
    {
        selectedCamera = GetComponent<Camera>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.mouseScrollDelta.y > 0)
        {
            selectedCamera.fieldOfView--;
            Debug.Log("Scrollwheel up working");
        }

        {
            if (Input.mouseScrollDelta.y < 0)
            {
                selectedCamera.fieldOfView++;
                Debug.Log("Scrollwheel down working");
            }
        }
    }
}


It works, but the camera FOV is snapped back to default settings, which leads me to believe a state or viewtype preset is setting the field of view back to 60 on update().

What would be the best practise/approach to solving this?

I was wondering if I ought to create a viewtype and/or state that is conducive to scrollwheel zooming, but I woudl prefer avoiding writing something from scratch, all just to zoom. What would be a good starting point for overriding or atleast prevent whatever it is that sets the FOV back to some pre-determiend value on update?

Thank you for your time.
 
Step zooming is already built into the third person view type but when you zoom it doesn't change the field of view. One way to accomplish this would be to subclass the Adventure View Type and then list for the OnThirdPersonViewTypeStepZoom event. When this event is called you can then change the m_FieldOfView parameter
 
Top