add unity project
add FSM examples
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user