campfire/Assets/Scripts/CameraController.cs

41 lines
1.3 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-19 22:09:31 +02:00
Eulers.y += Input.GetAxis("Mouse X") * Options.MouseSensitivity * (Options.InvertMouseX ? -1 : 1);
2020-04-18 18:26:35 +02:00
BodyTransform.localEulerAngles = Eulers;
Eulers = HeadTransform.localEulerAngles;
2020-04-19 22:09:31 +02:00
Eulers.x -= Input.GetAxis("Mouse Y") * 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
}
}
}