using System; using UnityEngine; using UnityEngine.EventSystems; using UInput = UnityEngine.Input; namespace UIWidgetsSample.RaycastableScene { public class DragRotate : MonoBehaviour { Vector2? _lastPosition = Vector2.zero; public static Vector2 mousePosition { get { return new Vector2(UInput.mousePosition.x, UInput.mousePosition.y); } } void OnMouseDown() { _lastPosition = mousePosition; } private void OnMouseUp() { _lastPosition = null; } private void OnMouseDrag() { Vector2 direction = mousePosition - _lastPosition.Value; _lastPosition = mousePosition; transform.Rotate(-direction.y, -direction.x, 0, Space.World); } } }