43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class BasicEnemyStateController : MonoBehaviour
|
||
|
{
|
||
|
IState currentState;
|
||
|
BasicenemyBaseState currentStatee;
|
||
|
public BasicEnemyPatrolState patrolState = new BasicEnemyPatrolState();
|
||
|
public BasicEnemyMovingState movingState = new BasicEnemyMovingState();
|
||
|
public BasicEnemyShootingState ShootingState = new BasicEnemyShootingState();
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
ChangeState(patrolState);
|
||
|
}
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
if(currentState != null)
|
||
|
{
|
||
|
currentState.UpdateState(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void ChangeState(IState newState)
|
||
|
{
|
||
|
if(currentState != null)
|
||
|
{
|
||
|
currentState.OnExit(this);
|
||
|
}
|
||
|
currentState = newState;
|
||
|
currentState.OnEnter(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public interface IState
|
||
|
{
|
||
|
public void OnEnter(BasicEnemyStateController controller);
|
||
|
public void UpdateState(BasicEnemyStateController controller);
|
||
|
public void OnExit(BasicEnemyStateController controller);
|
||
|
}
|