add unity project

add example for FSM
This commit is contained in:
2025-04-08 13:03:11 +02:00
parent 7e484e4831
commit 19a08085fe
81 changed files with 7741 additions and 0 deletions
@@ -0,0 +1,49 @@
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)
{
}
}
}