BehaviorTree / Runtime / Components / BehaviorTreeComponent.cs
BehaviorTreeComponent.cs
Raw
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

namespace AI.BT
{
    [RequireComponent(typeof(NavMeshAgent))]
    public class BehaviorTreeComponent : MonoBehaviour
    {
        public BehaviorTree m_BehaviorTree;

        // Start is called before the first frame update
        void Start()
        {
            if(m_BehaviorTree)
            {
                m_BehaviorTree = m_BehaviorTree.Clone();
            }
        }

        // Update is called once per frame
        void Update()
        {
            if(m_BehaviorTree)
            {
                m_BehaviorTree.Execute(GetComponent<NavMeshAgent>(), Time.deltaTime);
            }
        }
    }
}