暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EnableIffSleeping.cs 779B

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