Start AI COntroller
This commit is contained in:
39
Assets/Scripts/Control/AIController.cs
Normal file
39
Assets/Scripts/Control/AIController.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user