WindowDragTilt.cs 691 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Window Drag Tilt")]
  4. public class WindowDragTilt : MonoBehaviour
  5. {
  6. private void OnEnable()
  7. {
  8. this.mTrans = base.transform;
  9. this.mLastPos = this.mTrans.position;
  10. }
  11. private void Update()
  12. {
  13. Vector3 vector = this.mTrans.position - this.mLastPos;
  14. this.mLastPos = this.mTrans.position;
  15. this.mAngle += vector.x * this.degrees;
  16. this.mAngle = NGUIMath.SpringLerp(this.mAngle, 0f, 20f, Time.deltaTime);
  17. this.mTrans.localRotation = Quaternion.Euler(0f, 0f, -this.mAngle);
  18. }
  19. public int updateOrder;
  20. public float degrees = 30f;
  21. private Vector3 mLastPos;
  22. private Transform mTrans;
  23. private float mAngle;
  24. }