campfire/Assets/Scripts/CameraController.cs

49 lines
1.5 KiB
C#
Raw Normal View History

2020-04-18 18:26:35 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour {
2020-04-19 01:12:29 +02:00
public GameState GameState;
2020-04-19 22:09:31 +02:00
public Options Options;
2020-04-18 18:26:35 +02:00
public Transform BodyTransform;
public Transform HeadTransform;
private PauseMenu Menu;
private void Awake() {
Menu = GameObject.FindGameObjectWithTag("Pause Menu").GetComponent<PauseMenu>();
}
private void Update() {
2020-04-19 01:12:29 +02:00
if (GameState.Current == State.Playing) {
2020-04-18 18:26:35 +02:00
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
Vector3 Eulers = BodyTransform.localEulerAngles;
2020-04-20 01:20:02 +02:00
Eulers.y += GetHorizontalLookDelta() * Options.MouseSensitivity * (Options.InvertMouseX ? -1 : 1);
2020-04-18 18:26:35 +02:00
BodyTransform.localEulerAngles = Eulers;
Eulers = HeadTransform.localEulerAngles;
2020-04-20 01:20:02 +02:00
Eulers.x -= GetVerticalLookDelta() * Options.MouseSensitivity * (Options.InvertMouseY ? -1 : 1);
2020-04-18 18:26:35 +02:00
if (Eulers.x > 90 && Eulers.x < 180) {
Eulers.x = 90;
}
if (Eulers.x < 270 && Eulers.x > 180) {
Eulers.x = 270;
}
HeadTransform.localEulerAngles = Eulers;
2020-04-19 01:12:29 +02:00
} else {
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
2020-04-18 18:26:35 +02:00
}
}
2020-04-20 01:20:02 +02:00
private float GetHorizontalLookDelta() {
return Input.GetAxis("Mouse X");
}
private float GetVerticalLookDelta() {
return Input.GetAxis("Mouse Y");
}
2020-04-18 18:26:35 +02:00
}