You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
766 B
C#
32 lines
766 B
C#
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
public class Zoom : MonoBehaviour
|
|
{
|
|
Camera camera;
|
|
public float defaultFOV = 60;
|
|
public float maxZoomFOV = 15;
|
|
[Range(0, 1)]
|
|
public float currentZoom;
|
|
public float sensitivity = 1;
|
|
|
|
|
|
void Awake()
|
|
{
|
|
// Get the camera on this gameObject and the defaultZoom.
|
|
camera = GetComponent<Camera>();
|
|
if (camera)
|
|
{
|
|
defaultFOV = camera.fieldOfView;
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
// Update the currentZoom and the camera's fieldOfView.
|
|
currentZoom += Input.mouseScrollDelta.y * sensitivity * .05f;
|
|
currentZoom = Mathf.Clamp01(currentZoom);
|
|
camera.fieldOfView = Mathf.Lerp(defaultFOV, maxZoomFOV, currentZoom);
|
|
}
|
|
}
|