You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.6 KiB
53 lines
1.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MouseControl : MonoBehaviour
|
|
{
|
|
public Vector3 offset;
|
|
public GameObject camera;
|
|
float _rotationX;
|
|
public Transform player;
|
|
public static MouseControl _instance;
|
|
|
|
private void Awake()
|
|
{
|
|
_instance = this;
|
|
}
|
|
private void Start()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
}
|
|
private void Update()
|
|
{
|
|
|
|
if (Input.GetKey(KeyCode.LeftAlt))
|
|
{
|
|
Cursor.lockState = CursorLockMode.None;
|
|
GameManager.GetInstance().IsMoveCursor = false;
|
|
Cursor.visible = true;
|
|
}
|
|
if (!Input.GetKey(KeyCode.LeftAlt))
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
GameManager.GetInstance().IsMoveCursor = true;
|
|
if (GameManager.GetInstance().IsOpenUI)
|
|
{
|
|
GameManager.GetInstance().IsMoveCursor = false;
|
|
}
|
|
}
|
|
|
|
if (!GameManager.GetInstance().IsMoveCursor) return;
|
|
float rotationY = camera.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * 1.5f;
|
|
_rotationX -= Input.GetAxis("Mouse Y") * 1.5f;
|
|
_rotationX = Mathf.Clamp(_rotationX, -45, 45);
|
|
camera.transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
|
|
|
|
float rotationY1 = player.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * 1.5f;
|
|
player.transform.localEulerAngles = new Vector3(0, rotationY1, 0);
|
|
|
|
camera.transform.position = player.position + offset;
|
|
}
|
|
}
|