Hey I have a building that I want to find the nearest enemy via another scrip I have where I store the enemy’s how do I make the building get the enemy list and then find the nearest enemy
i have defined the enemy list
enemiesManager = FindObjectOfType();
this is my targetfinder where the enemies should be from the enemies list
public void TargetFinder()
{
currentTargetDistance = Mathf.Infinity;
foreach (var x in enemies)
{
float distance = Vector3.Distance(transform.position, x.transform.position);
if (distance < currentTargetDistance)
{
myTarget = x;
displayText.text = "My target: " + x + "
Distance to Target: " + distance; //skal fjernes nå det er helt klart
currentTargetDistance = distance;
}
}
}
this is the enemy list
public class EnemiesManager : MonoBehaviour
{
public List<GameObject> _allEnemies = new List<GameObject>();
public static EnemiesManager Current;
private void Awake()
{
if (Current == null)
Current = this;
}
}