RotateBody.cs 911 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Funly.SkyStudio {
  5. // Rotates along the z-axis to spin the sun or moon textures.
  6. public class RotateBody : MonoBehaviour {
  7. private float m_SpinSpeed;
  8. public float SpinSpeed {
  9. get { return m_SpinSpeed; }
  10. set {
  11. m_SpinSpeed = value;
  12. UpdateOrbitBodyRotation();
  13. }
  14. }
  15. private bool m_AllowSpinning;
  16. public bool AllowSpinning {
  17. get { return m_AllowSpinning; }
  18. set {
  19. m_AllowSpinning = value;
  20. UpdateOrbitBodyRotation();
  21. }
  22. }
  23. public void UpdateOrbitBodyRotation() {
  24. float allowOrClear = m_AllowSpinning ? 1 : 0;
  25. Vector3 rot = this.transform.localRotation.eulerAngles;
  26. Vector3 rotSpin = new Vector3(
  27. 0.0f,
  28. -180.0f,
  29. (rot.z + (-10.0f * SpinSpeed * Time.deltaTime)) * allowOrClear
  30. );
  31. this.transform.localRotation = Quaternion.Euler(rotSpin);
  32. }
  33. }
  34. }