Files
3DBlobici-WorkingTitle/3D blobici/Assets/Scripts/Player/CameraZoom.cs

28 lines
763 B
C#

using UnityEngine;
public class CameraZoom : MonoBehaviour
{
public float zoomSpeed = 10f; // Speed of zooming
public float minZoom = 5f; // Minimum zoom distance
public float maxZoom = 20f; // Maximum zoom distance
private Camera cam;
void Start()
{
cam = GetComponent<Camera>(); // Get the Camera component attached to the GameObject
}
void Update()
{
// Get the scroll wheel input
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
// Calculate the new field of view (FOV)
float newFOV = cam.fieldOfView - scrollInput * zoomSpeed;
// Clamp the FOV to be within the min and max zoom distances
cam.fieldOfView = Mathf.Clamp(newFOV, minZoom, maxZoom);
}
}