35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class Enemy : Entity
|
|
{
|
|
public int turnSpeed;
|
|
public int minimumAttackRange;
|
|
private PlayerEntity closestPlayer;
|
|
|
|
void Start()
|
|
{
|
|
turnSpeed = Random.Range(0, 100);
|
|
}
|
|
|
|
[ContextMenu("ForceTurn")]
|
|
public void StartTurn()
|
|
{
|
|
TurnHandler.instance.UpdateTurns();
|
|
closestPlayer = FindClosestPlayer();
|
|
Debug.Log(closestPlayer);
|
|
EnemyMovement.instance.PathfindToTarget(closestPlayer.currentTile.neighbors[Random.Range(0, closestPlayer.currentTile.neighbors.Count)], this);
|
|
}
|
|
|
|
private PlayerEntity FindClosestPlayer()
|
|
{
|
|
PlayerEntity currentClosestPlayer = null;
|
|
foreach (PlayerEntity player in TurnHandler.instance.playerEntities)
|
|
{
|
|
if (!currentClosestPlayer || Vector3.Distance(player.transform.position, transform.position) < Vector3.Distance(currentClosestPlayer.transform.position, transform.position))
|
|
{
|
|
currentClosestPlayer = player;
|
|
}
|
|
}
|
|
return currentClosestPlayer;
|
|
}
|
|
}
|