39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class CameraController : MonoBehaviour {
|
|||
|
public Transform BodyTransform;
|
|||
|
public Transform HeadTransform;
|
|||
|
|
|||
|
private PauseMenu Menu;
|
|||
|
|
|||
|
private void Awake() {
|
|||
|
Menu = GameObject.FindGameObjectWithTag("Pause Menu").GetComponent<PauseMenu>();
|
|||
|
}
|
|||
|
|
|||
|
private void Update() {
|
|||
|
if (Menu.Paused) {
|
|||
|
Cursor.visible = true;
|
|||
|
Cursor.lockState = CursorLockMode.None;
|
|||
|
} else {
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|