Spin.cs 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Spin")]
  4. public class Spin : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. this.mTrans = base.transform;
  9. this.mRb = base.GetComponent<Rigidbody>();
  10. }
  11. private void Update()
  12. {
  13. if (this.mRb == null)
  14. {
  15. this.ApplyDelta((!this.ignoreTimeScale) ? Time.deltaTime : RealTime.deltaTime);
  16. }
  17. }
  18. private void FixedUpdate()
  19. {
  20. if (this.mRb != null)
  21. {
  22. this.ApplyDelta(Time.deltaTime);
  23. }
  24. }
  25. public void ApplyDelta(float delta)
  26. {
  27. delta *= 360f;
  28. Quaternion rhs = Quaternion.Euler(this.rotationsPerSecond * delta);
  29. if (this.mRb == null)
  30. {
  31. this.mTrans.rotation = this.mTrans.rotation * rhs;
  32. }
  33. else
  34. {
  35. this.mRb.MoveRotation(this.mRb.rotation * rhs);
  36. }
  37. }
  38. public Vector3 rotationsPerSecond = new Vector3(0f, 0.1f, 0f);
  39. public bool ignoreTimeScale;
  40. private Rigidbody mRb;
  41. private Transform mTrans;
  42. }