using UnityEngine; using MyCollections.AI.FinitStateMachine; [CreateAssetMenu(menuName = "Finite State Machine/Action/Warn")] public class WarnAction : Action { [SerializeField] private float warnRadius = 5f; //The radius of the circle [SerializeField] private LayerMask targetLayerMask; //target LayerMask //The NPC will warn the other npc's nearby about the target spoted public override void Run(FSM fsm) { GameObject target = fsm.Controller.AgentFOV.GetTarget(); if (target == null) { Debug.LogError("Target is NULL"); return; } Collider2D collider = Physics2D.OverlapCircle(fsm.transform.position, warnRadius, targetLayerMask); if (collider != null) { if (collider.TryGetComponent(out NPCController c)) { c.AgentFOV.SetTarget(target); fsm.Controller.NPCManager.OnTargetSpoted.Invoke(target, fsm.Controller); } } } }