DiveMouseLook.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using UnityEngine;
  2. using System.Collections;
  3. public class DiveMouseLook : MonoBehaviour {
  4. public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
  5. public RotationAxes axes = RotationAxes.MouseXAndY;
  6. public float sensitivityX = 15F;
  7. public float sensitivityY = 15F;
  8. public float minimumX = -360F;
  9. public float maximumX = 360F;
  10. public float minimumY = -60F;
  11. public float maximumY = 60F;
  12. float rotationY = 0F;
  13. bool mouse_on=true;
  14. void Update ()
  15. {
  16. if (mouse_on){
  17. if (axes == RotationAxes.MouseXAndY)
  18. {
  19. float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
  20. rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
  21. rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
  22. transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
  23. }
  24. else if (axes == RotationAxes.MouseX)
  25. {
  26. transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
  27. }
  28. else
  29. {
  30. rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
  31. rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
  32. transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
  33. }
  34. }
  35. }
  36. void Start ()
  37. {
  38. if (Application.platform == RuntimePlatform.Android)
  39. mouse_on=false;
  40. else if(Application.platform == RuntimePlatform.IPhonePlayer)
  41. mouse_on=false;
  42. // Make the rigid body not change rotation
  43. if (GetComponent<Rigidbody>())
  44. GetComponent<Rigidbody>().freezeRotation = true;
  45. }
  46. }