46 lines
927 B
C#
46 lines
927 B
C#
using UnityEngine;
|
|
|
|
namespace RootMotion
|
|
{
|
|
public class CameraControllerFPS : MonoBehaviour
|
|
{
|
|
public float rotationSensitivity = 3f;
|
|
|
|
public float yMinLimit = -89f;
|
|
|
|
public float yMaxLimit = 89f;
|
|
|
|
private float x;
|
|
|
|
private float y;
|
|
|
|
private void Awake()
|
|
{
|
|
Vector3 eulerAngles = base.transform.eulerAngles;
|
|
x = eulerAngles.y;
|
|
y = eulerAngles.x;
|
|
}
|
|
|
|
public void LateUpdate()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
x += Input.GetAxis("Mouse X") * rotationSensitivity;
|
|
y = ClampAngle(y - Input.GetAxis("Mouse Y") * rotationSensitivity, yMinLimit, yMaxLimit);
|
|
base.transform.rotation = Quaternion.AngleAxis(x, Vector3.up) * Quaternion.AngleAxis(y, Vector3.right);
|
|
}
|
|
|
|
private float ClampAngle(float angle, float min, float max)
|
|
{
|
|
if (angle < -360f)
|
|
{
|
|
angle += 360f;
|
|
}
|
|
if (angle > 360f)
|
|
{
|
|
angle -= 360f;
|
|
}
|
|
return Mathf.Clamp(angle, min, max);
|
|
}
|
|
}
|
|
}
|