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.
52 lines
1.2 KiB
52 lines
1.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MouseRote : MonoBehaviour
|
|
{
|
|
//sensitivity => ÁéÃô¶È
|
|
public float MouseSensitivity = 100f;
|
|
public float moveSpeed=5f;
|
|
|
|
private float XRotation = 0f;
|
|
private float _rotationX;
|
|
|
|
private bool canrote = true;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.LeftAlt))
|
|
{
|
|
if(Cursor.lockState== CursorLockMode.Locked)
|
|
{
|
|
Cursor.lockState = CursorLockMode.None;
|
|
canrote = false;
|
|
}
|
|
else if (Cursor.lockState == CursorLockMode.None)
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
canrote = true;
|
|
}
|
|
}
|
|
|
|
if (canrote)
|
|
{
|
|
|
|
float rotationY = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * 2;
|
|
_rotationX -= Input.GetAxis("Mouse Y") * 2;
|
|
_rotationX = Mathf.Clamp(_rotationX, -45, 45);
|
|
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|