Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / Orc / Conditions / CanAttack.cs
@Rackday Rackday on 29 Oct 920 bytes Major Update
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using MyCollections.AI.FinitStateMachine;
  5. [CreateAssetMenu(menuName = "Finite State Machine/Condition/CanAttack")]
  6. public class CanAttack : Condition
  7. {
  8. [SerializeField] private float distance; //Minimum distance
  9. public override bool CheckCondition(FSM fsm)
  10. {
  11. if (fsm.Controller.AgentFOV.GetTarget() != null)
  12. {
  13. OrcNPCController npcController = fsm.Controller as OrcNPCController;
  14. if(npcController != null)
  15. {
  16. //if the npc attacktimer is reseted and the distance is close enough to the target
  17. return fsm.Controller.AgentFOV.TargetDistance <= distance && npcController.AttackTimer >= npcController.MaxAttackTimer;
  18. }
  19. Debug.LogError("Controller is null");
  20. return false;
  21. }
  22. return false;
  23. }
  24. }