add unity project

add FSM examples
This commit is contained in:
2025-04-09 07:51:22 +02:00
parent 8f18ee3b79
commit fccc1849fe
81 changed files with 7706 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
using UnityEngine;
namespace DefaultNamespace.FSM
{
public class ChasePlayerState : IState
{
private GameObject _owner;
private PlayerController _player;
public ChasePlayerState(GameObject owner, PlayerController player)
{
_owner = owner;
_player = player;
}
public void Enter(IFiniteStateMachine ctx)
{
Debug.Log("CHASE: Enter");
}
public void Update(IFiniteStateMachine ctx)
{
Debug.Log("CHASE: Update");
// player visibility check
if (Physics.Raycast(_owner.transform.position, _owner.transform.forward, out RaycastHit hit))
{
if (hit.transform.GetComponent<PlayerController>() != _player)
{
ctx.SetState(new IdleState(_owner, _player, 60.0f));
}
}
else
{
ctx.SetState(new IdleState(_owner, _player, 60.0f));
}
}
public void Exit(IFiniteStateMachine ctx)
{
Debug.Log("CHASE: Exit");
}
}
}