Newer
Older
HierarchicalFSM-Unity3D / Assets / Scripts / NPC / FSM / Conditions / CheckTargetState.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5. using UnityEngine.AI;
  6. [CreateAssetMenu(menuName = "Finite State Machine/Condition/CheckTargetState")]
  7. public class CheckTargetState : Condition
  8. {
  9. [SerializeField] private IState.TargetState targetState;
  10. //Find Cover Location
  11. public override bool CheckCondition(FSM fsm)
  12. {
  13. GameObject target = fsm.Controller.AgentFOV.GetTarget();
  14. if (target != null)
  15. {
  16. if (target.TryGetComponent(out IState state))
  17. {
  18. if (targetState == state.GetState())
  19. {
  20. return true;
  21. }
  22. else
  23. {
  24. return false;
  25. }
  26. }
  27. else
  28. {
  29. Debug.LogError($"Component not Found: {nameof(IState)}");
  30. return false;
  31. }
  32. }
  33. else
  34. {
  35. Debug.LogWarning($"Target Missing!");
  36. return false;
  37. }
  38. }
  39. }