123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using UnityEngine;
- using System.Collections;
- public class DiveMouseLook : MonoBehaviour {
- public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
- public RotationAxes axes = RotationAxes.MouseXAndY;
- public float sensitivityX = 15F;
- public float sensitivityY = 15F;
- public float minimumX = -360F;
- public float maximumX = 360F;
- public float minimumY = -60F;
- public float maximumY = 60F;
- float rotationY = 0F;
- bool mouse_on=true;
- void Update ()
- {
- if (mouse_on){
-
- if (axes == RotationAxes.MouseXAndY)
- {
- float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
-
- rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
- rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
-
- transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
- }
- else if (axes == RotationAxes.MouseX)
- {
- transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
- }
- else
- {
- rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
- rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
-
- transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
- }
- }
- }
-
- void Start ()
- {
- if (Application.platform == RuntimePlatform.Android)
- mouse_on=false;
- else if(Application.platform == RuntimePlatform.IPhonePlayer)
- mouse_on=false;
- // Make the rigid body not change rotation
- if (GetComponent<Rigidbody>())
- GetComponent<Rigidbody>().freezeRotation = true;
- }
- }
|