Added: Unity Behavior Graph asset for behaviour demo
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AI.BehaviourTree
|
||||
{
|
||||
public class BehaviourTree : MonoBehaviour
|
||||
{
|
||||
private Node rootNode;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
NodeStatus status = rootNode.Start();
|
||||
Debug.Log("Behaviour tree started");
|
||||
Debug.Log($"Behaviour tree start root node status: {status}");
|
||||
if (status != NodeStatus.Running) enabled = false;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Debug.Log("Behaviour tree stopped");
|
||||
rootNode.Stop();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
NodeStatus status = rootNode.Execute();
|
||||
Debug.Log($"Behaviour tree execute root node status: {status}");
|
||||
if (status != NodeStatus.Running) enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user