36 lines
776 B
C#
Raw Normal View History

2020-03-08 12:32:41 +01:00
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");
}
}
}