74 lines
1.5 KiB
C#
74 lines
1.5 KiB
C#
using UnityEngine;
|
|
|
|
[AddComponentMenu("Camera-Control/Mouse Look")]
|
|
public class MouseLookSKYMASTER : MonoBehaviour
|
|
{
|
|
public enum RotationAxes
|
|
{
|
|
MouseXAndY = 0,
|
|
MouseX = 1,
|
|
MouseY = 2
|
|
}
|
|
|
|
public RotationAxes axes;
|
|
|
|
public float sensitivityX = 15f;
|
|
|
|
public float sensitivityY = 15f;
|
|
|
|
public float minimumX = -360f;
|
|
|
|
public float maximumX = 360f;
|
|
|
|
public float minimumY = -60f;
|
|
|
|
public float maximumY = 60f;
|
|
|
|
private float rotationY;
|
|
|
|
public bool Menabled;
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown("space"))
|
|
{
|
|
if (Menabled)
|
|
{
|
|
Menabled = false;
|
|
}
|
|
else
|
|
{
|
|
Menabled = true;
|
|
}
|
|
}
|
|
if (Menabled)
|
|
{
|
|
if (axes == RotationAxes.MouseXAndY)
|
|
{
|
|
float y = base.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
|
|
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
|
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
|
|
base.transform.localEulerAngles = new Vector3(0f - rotationY, y, 0f);
|
|
}
|
|
else if (axes == RotationAxes.MouseX)
|
|
{
|
|
base.transform.Rotate(0f, Input.GetAxis("Mouse X") * sensitivityX, 0f);
|
|
}
|
|
else
|
|
{
|
|
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
|
|
rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
|
|
base.transform.localEulerAngles = new Vector3(0f - rotationY, base.transform.localEulerAngles.y, 0f);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if ((bool)GetComponent<Rigidbody>())
|
|
{
|
|
GetComponent<Rigidbody>().freezeRotation = true;
|
|
}
|
|
}
|
|
}
|