using System; using UnityEngine; namespace DefaultNamespace.FSM { [Serializable] public class PlayerDetectedState : IState { [SerializeField] private float _radius; private GameObject _owner; private PlayerController _playerController; public PlayerDetectedState(GameObject owner, PlayerController player, float radius) { _owner = owner; _playerController = player; _radius = radius; } public void Enter(IFiniteStateMachine ctx) { } public void Update(IFiniteStateMachine ctx) { // get distance to player float distance = Vector3.Distance(_owner.transform.position, _playerController.transform.position); // compare to radius if (distance < _radius) { // set to is in range state Debug.Log("Player is in range"); } else { // set to is out of range state Debug.Log("Player is out of range"); } } public void Exit(IFiniteStateMachine ctx) { } } }