init
This commit is contained in:
29
Assets/Scripts/Camera/CameraController.cs
Normal file
29
Assets/Scripts/Camera/CameraController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user