campfire/Assets/Scripts/CameraController.cs

40 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour {
public GameState GameState;
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 += Input.GetAxis("Mouse X");
BodyTransform.localEulerAngles = Eulers;
Eulers = HeadTransform.localEulerAngles;
Eulers.x -= Input.GetAxis("Mouse Y");
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;
}
}
}