44 lines
1.1 KiB
C#
44 lines
1.1 KiB
C#
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");
|
|
}
|
|
}
|
|
} |