-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraController.cs
59 lines (47 loc) · 1.55 KB
/
CameraController.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private Camera cam;
float sensitivityX = 15F;
float sensitivityY = 15F;
//float minimumX = -340F;
//float maximumX = 340F;
float minimumY = -60F;
float maximumY = 60F;
private static float rotationX = 0F;
float rotationY = 0F;
public static float getRotationY()
{
return rotationX;
}
public static float ClampAngle(float angle, float min, float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp(angle, min, max);
}
// Start is called before the first frame update
void Start()
{
cam = Camera.main;
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift)) Cursor.lockState = CursorLockMode.None;
if (Input.GetKeyDown(KeyCode.LeftControl)) Cursor.lockState = CursorLockMode.Locked;
float zoom = Input.GetAxis("Mouse ScrollWheel") * 20f;
cam.fieldOfView += zoom;
cam.fieldOfView = Mathf.Clamp(cam.fieldOfView, 60f, 120f);
// Read the mouse input axis
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = ClampAngle(rotationY, minimumY, maximumY);
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
}