mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 00:58:59 -05:00
36 lines
776 B
C#
36 lines
776 B
C#
using UnityEngine;
|
|
using UnityAtoms.BaseAtoms;
|
|
using UnityAtoms.Tags;
|
|
using UnityAtoms.FSM;
|
|
|
|
public class EnemyState : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private StringReference _tagToTarget;
|
|
|
|
[SerializeField]
|
|
private FloatReference _shotRange = new FloatReference(5f);
|
|
|
|
[SerializeField]
|
|
private FiniteStateMachine _enemtStateMachine;
|
|
|
|
private Transform _target;
|
|
|
|
void Start()
|
|
{
|
|
_enemtStateMachine.Begin();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (_enemtStateMachine.Value != "ATTACKING" && _shotRange.Value >= Vector3.Distance(_target.position, transform.position))
|
|
{
|
|
_enemtStateMachine.Dispatch("ATTACK");
|
|
}
|
|
else
|
|
{
|
|
_enemtStateMachine.Dispatch("CHASE");
|
|
}
|
|
}
|
|
}
|