Files
HauntedBloodlines/Assets/Samples/AI Navigation/1.0.0-exp.4/Build And Connect NavMesh Surfaces/Scripts/EnableIffSleeping.cs
2025-05-29 22:31:40 +03:00

31 lines
779 B
C#

using UnityEngine;
namespace Unity.AI.Navigation.Samples
{
/// <summary>
/// Enables a behaviour when a rigidbody settles movement
/// otherwise disables the behaviour
/// </summary>
public class EnableIffSleeping : MonoBehaviour
{
public Behaviour m_Behaviour;
Rigidbody m_Rigidbody;
void Start()
{
m_Rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
if (m_Rigidbody == null || m_Behaviour == null)
return;
if (m_Rigidbody.IsSleeping() && !m_Behaviour.enabled)
m_Behaviour.enabled = true;
if (!m_Rigidbody.IsSleeping() && m_Behaviour.enabled)
m_Behaviour.enabled = false;
}
}
}