39 lines
928 B
C#
39 lines
928 B
C#
using RPG.Combat;
|
|
using RPG.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
namespace RPG.Control
|
|
{
|
|
public class AIController : MonoBehaviour,IAction
|
|
{
|
|
[SerializeField] float chaseDistance = 5f;
|
|
Fighter fighter;
|
|
GameObject player;
|
|
void Start()
|
|
{
|
|
fighter = GetComponent<Fighter>();
|
|
player = GameObject.FindWithTag("Player");
|
|
}
|
|
void Update()
|
|
{
|
|
if (InAttackRangeOfPlayer() && fighter.CanAttack(player))
|
|
fighter.Attack(player);
|
|
else
|
|
{
|
|
fighter.Cancel();
|
|
}
|
|
}
|
|
|
|
private bool InAttackRangeOfPlayer()
|
|
{
|
|
float distanceToPlayer = Vector3.Distance(player.transform.position, transform.position);
|
|
return distanceToPlayer < chaseDistance;
|
|
}
|
|
|
|
public void Cancel()
|
|
{
|
|
|
|
}
|
|
}
|
|
} |