CUI_CameraRotationOnButtonHeld.cs 811 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using UnityEngine;
  2. using System.Collections;
  3. public class CUI_CameraRotationOnButtonHeld : MonoBehaviour {
  4. [SerializeField]
  5. float Sensitivity = 0.5f;
  6. Vector3 oldMousePos;
  7. bool move = true;
  8. // Use this for initialization
  9. void Start () {
  10. oldMousePos = Input.mousePosition;
  11. }
  12. #if UNITY_EDITOR
  13. // Update is called once per frame
  14. void Update() {
  15. if (Input.GetButton("Fire2"))
  16. {
  17. move = true;
  18. }
  19. else
  20. move = false;
  21. if (move)
  22. {
  23. Vector2 mouseDelta = Input.mousePosition - oldMousePos;
  24. this.transform.eulerAngles = this.transform.eulerAngles + new Vector3(mouseDelta.y, -mouseDelta.x, 0) * Sensitivity;
  25. }
  26. oldMousePos = Input.mousePosition;
  27. }
  28. #endif
  29. }