Narratech_TFG-Fernandez/HTN NPC/Assets/Scripts/EnemyController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyController : MonoBehaviour
{
    public Transform[] wayPoints;

    private NavMeshAgent agent;

    private WorldState worldState;
    private Planner planner;
    private CompoundTask root;

    private void Start()
    {
        agent = GetComponent<NavMeshAgent>();

        worldState = new WorldState();

        root = new CompoundTask(CompoundType.Selector);

        planner = new Planner(root, worldState);

        PrimitiveTask patrolTask = new PrimitiveTask();
        root.AddTask(patrolTask);

        MoveTo moveTo = new MoveTo(agent, wayPoints);
        patrolTask.SetOperator(moveTo);
    }

    private void Update()
    {
        planner.RunPlan();
    }
}
