MIF_E31222569/Assets/ToothyV/Scripts/Gameplay/Agent.cs

66 lines
1.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Agent : MonoBehaviour
{
public AgentInput AgentInput;
public AgentAnimator AgentAnimator;
public ObjectPool ObjectPool;
[SerializeField]
private State currentState, previousState;
[SerializeField]
private State idleState;
[SerializeField] private string debugState;
private void Awake()
{
State[] states = GetComponentsInChildren<State>();
foreach (State state in states)
{
state.Initialize(this);
}
}
private void Start()
{
TransitionTo(idleState);
}
private void Update()
{
currentState.UpdateState();
}
public void TransitionTo(State desireState)
{
if (currentState != null)
{
currentState.Exit();
}
previousState = currentState;
currentState = desireState;
currentState.Enter();
DisplayInfoState();
}
public void DisplayInfoState()
{
if (previousState == null || previousState.GetType() != currentState.GetType())
{
debugState = currentState.GetType().ToString();
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Enemy"))
{
GameOver.Open();
}
}
}