This commit is contained in:
2025-05-28 10:05:03 +08:00
parent 45c935c5b6
commit ecd25ce410
3706 changed files with 715515 additions and 20 deletions

View File

@@ -0,0 +1,31 @@
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);
}
}