nahraná dosavadní verze hry
This commit is contained in:
27
3D blobici/Assets/Scripts/Player/CameraZoom.cs
Normal file
27
3D blobici/Assets/Scripts/Player/CameraZoom.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user