Files
No-Time-To-Rest/Assets/Scripts/Player/CameraMovement.cs
T
KOSMOGOR 2869bfdb33 add: Level and Game controllers base
update: scripts are now in folders
2025-03-17 15:28:10 +03:00

28 lines
803 B
C#

using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public float horSpeed = 20f;
public float verSpeed = 20f;
public float verUpperBound = 45f;
public float verLowerBound = -45f;
private float verRotation = 0f;
private Camera cam;
void Start() {
cam = GetComponentInChildren<Camera>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update() {
float horRotation = Input.GetAxis("Mouse X") * Time.deltaTime * horSpeed;
transform.Rotate(0, horRotation, 0);
verRotation -= Input.GetAxis("Mouse Y") * Time.deltaTime * verSpeed;
verRotation = Mathf.Clamp(verRotation, verLowerBound, verUpperBound);
cam.transform.localEulerAngles = new(verRotation, 0, 0);
}
}