70 lines
1.5 KiB
C#
70 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Agent : MonoBehaviour
|
|
{
|
|
public AgentInput AgentInput;
|
|
public AgentAnimator AgentAnimator;
|
|
public AgentRenderer AgentRenderer;
|
|
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);
|
|
AgentRenderer = GetComponentInChildren<AgentRenderer>();
|
|
}
|
|
|
|
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"))
|
|
{
|
|
audioController.Instance.PlaySFX("sfx_Dead");
|
|
GameOver.Open();
|
|
}
|
|
}
|
|
}
|