Advertisement
Guest User

Untitled

a guest
Jan 4th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4.  
  5. enum Axis {
  6. X = 0,
  7. Y = 1,
  8. X_AND_Y = 2
  9. }
  10.  
  11. public class MouseLook : MonoBehaviour {
  12.  
  13. [SerializeField] private Axis axis = Axis.X_AND_Y;
  14.  
  15. private float sensitivity = 5f;
  16.  
  17. private float minimumY = -90f;
  18. private float maximumY = 90f;
  19.  
  20. private Vector2 angles = Vector2.zero;
  21.  
  22. void Start() {
  23. angles = transform.eulerAngles;
  24. }
  25.  
  26. // Update is called once per frame
  27. void Update () {
  28. if(Screen.showCursor) return;
  29.  
  30. float x = Input.GetAxis("Mouse X");
  31. float y = -Input.GetAxis("Mouse Y");
  32. Vector2 delta = new Vector2(y, x);
  33.  
  34. angles += delta * sensitivity;
  35. angles.x = Mathf.Clamp(angles.x, minimumY, maximumY);
  36.  
  37. if(axis == Axis.Y) angles.x = transform.localEulerAngles.x;
  38. if(axis == Axis.X) angles.y = transform.localEulerAngles.y;
  39.  
  40. Quaternion targetRotation = Quaternion.Euler(angles);
  41. transform.localRotation = Quaternion.Slerp( transform.localRotation, targetRotation, 25*Time.deltaTime );
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement