blob: c2da27bea675e4a0d639638baf02fb693945bf5b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
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;
}
}
}
|