Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / Orc / Conditions / CanAttack.cs
@Rackday Rackday on 29 Oct 920 bytes Major Update
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyCollections.AI.FinitStateMachine;

[CreateAssetMenu(menuName = "Finite State Machine/Condition/CanAttack")]
public class CanAttack : Condition
{
    [SerializeField] private float distance; //Minimum distance

    public override bool CheckCondition(FSM fsm)
    {
        if (fsm.Controller.AgentFOV.GetTarget() != null)
        {
            OrcNPCController npcController = fsm.Controller as OrcNPCController;

            if(npcController != null)
            {
                //if the npc attacktimer is reseted and the distance is close enough to the target
                return fsm.Controller.AgentFOV.TargetDistance <= distance && npcController.AttackTimer >= npcController.MaxAttackTimer;
            }

            Debug.LogError("Controller is null");
            return false;
        }

        return false;
    }
}