1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| using UnityEngine;
public class CameraZoom : MonoBehaviour
{
private Camera mainCamera;
public int[] zoomLevel = {60, 40, 20};
private int currentLevel;
private void Start()
{
mainCamera = GetComponent<Camera>();
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
currentLevel += 1;
if (currentLevel >= zoomLevel.Length)
{
currentLevel = 0;
}
}
int currentFieldOfView = zoomLevel[currentLevel];
mainCamera.fieldOfView = Mathf.Lerp(mainCamera.fieldOfView, currentFieldOfView, 0.1f);
}
}
|