- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [CreateAssetMenu(menuName = "Finite State Machine/Condition/Can See Condition")]
- public class CanSeeCondition : Condition
- {
- public float viewAngle;
- public float viewDistance;
- protected override bool Test(FiniteStateMachine fsm)
- {
- Transform target = fsm.target;
- if (target != null)
- {
- Vector3 direction = target.position - fsm.transform.position;
- float distance = direction.magnitude;
- float angle = Vector3.Angle(direction.normalized, fsm.transform.forward);
- return (angle < viewAngle && distance < viewDistance);
- } else
- {
- return false;
- }
- }
- }