49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CameraController : MonoBehaviour {
|
|
public GameState GameState;
|
|
public Options Options;
|
|
public Transform BodyTransform;
|
|
public Transform HeadTransform;
|
|
|
|
private PauseMenu Menu;
|
|
|
|
private void Awake() {
|
|
Menu = GameObject.FindGameObjectWithTag("Pause Menu").GetComponent<PauseMenu>();
|
|
}
|
|
|
|
private void Update() {
|
|
if (GameState.Current == State.Playing) {
|
|
Cursor.visible = false;
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
|
|
Vector3 Eulers = BodyTransform.localEulerAngles;
|
|
Eulers.y += GetHorizontalLookDelta() * Options.MouseSensitivity * (Options.InvertMouseX ? -1 : 1);
|
|
BodyTransform.localEulerAngles = Eulers;
|
|
|
|
Eulers = HeadTransform.localEulerAngles;
|
|
Eulers.x -= GetVerticalLookDelta() * Options.MouseSensitivity * (Options.InvertMouseY ? -1 : 1);
|
|
if (Eulers.x > 90 && Eulers.x < 180) {
|
|
Eulers.x = 90;
|
|
}
|
|
if (Eulers.x < 270 && Eulers.x > 180) {
|
|
Eulers.x = 270;
|
|
}
|
|
HeadTransform.localEulerAngles = Eulers;
|
|
} else {
|
|
Cursor.visible = true;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
}
|
|
}
|
|
|
|
private float GetHorizontalLookDelta() {
|
|
return Input.GetAxis("Mouse X");
|
|
}
|
|
|
|
private float GetVerticalLookDelta() {
|
|
return Input.GetAxis("Mouse Y");
|
|
}
|
|
}
|