EnableIffSleeping.cs 618 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. // Enables a behaviour when a rigidbody settles movement
  3. // otherwise disables the behaviour
  4. public class EnableIffSleeping : MonoBehaviour
  5. {
  6. public Behaviour m_Behaviour;
  7. Rigidbody m_Rigidbody;
  8. void Start()
  9. {
  10. m_Rigidbody = GetComponent<Rigidbody>();
  11. }
  12. void Update()
  13. {
  14. if (m_Rigidbody == null || m_Behaviour == null)
  15. return;
  16. if (m_Rigidbody.IsSleeping() && !m_Behaviour.enabled)
  17. m_Behaviour.enabled = true;
  18. if (!m_Rigidbody.IsSleeping() && m_Behaviour.enabled)
  19. m_Behaviour.enabled = false;
  20. }
  21. }