Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / Orc / Actions / IdleAction.cs
@Rackday Rackday on 3 Sep 966 bytes Minor Update
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyCollections.AI.FinitStateMachine;

[CreateAssetMenu(menuName = "Finite State Machine/Action/Idle")]
public class IdleAction : Action
{

    public override void Run(FSM fsm)
    {
        IdleState state = (IdleState)fsm.CurrentState();
        state.timer -= Time.deltaTime;
        if (state.timer <= 0f && !state.generated)
        {
            GenerateWaypoint(fsm.Controller.Agent);
            state.generated = true;
        }
    }

    private void GenerateWaypoint(Agent agent)
    {
        //Give agent a waypoint
        Node randomNode = agent.Grid.GetRandomWalkableNode();

        if (randomNode != null)
        {
            Vector2 targetPosition = randomNode.worldPos;
            Debug.Log($"TARGET POSITION: {targetPosition}");
            agent.SetDestination(targetPosition);
        }

        else Debug.LogError($"RANDOM NODE {randomNode}");
    }

}