29 lines
803 B
C#
29 lines
803 B
C#
using UnityEngine;
|
|
|
|
namespace Camera
|
|
{
|
|
public class CameraController : MonoBehaviour
|
|
{
|
|
public float mouseSensitivity = 100.0f;
|
|
public Transform playerBody;
|
|
|
|
private float _xRotation;
|
|
|
|
private void Start()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
|
|
var mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
|
|
|
|
_xRotation -= mouseY;
|
|
_xRotation = Mathf.Clamp(_xRotation, -90f, 90f);
|
|
|
|
transform.localRotation = Quaternion.Euler(_xRotation, 0f, 0f);
|
|
playerBody.Rotate(Vector3.up * mouseX);
|
|
}
|
|
}
|
|
} |