SpinWithMouse.cs 678 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Spin With Mouse")]
  4. public class SpinWithMouse : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. this.mTrans = base.transform;
  9. }
  10. private void OnDrag(Vector2 delta)
  11. {
  12. UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
  13. if (this.target != null)
  14. {
  15. this.target.localRotation = Quaternion.Euler(0f, -0.5f * delta.x * this.speed, 0f) * this.target.localRotation;
  16. }
  17. else
  18. {
  19. this.mTrans.localRotation = Quaternion.Euler(0f, -0.5f * delta.x * this.speed, 0f) * this.mTrans.localRotation;
  20. }
  21. }
  22. public Transform target;
  23. public float speed = 1f;
  24. private Transform mTrans;
  25. }