Hey so i have this script where i get the current target distance and it works fine when the target moves closer to the object but if the target moves further away it dosnt update the distance can somebody help me
public void TargetFinder()
{
foreach (var x in enemies)
{
float distance = (transform.position - x.transform.position).magnitude;
if (distance < currentTargetDistance)
{
myTarget = x;
displayText.text = "My target: " + x + "
Distance to Target: " + distance; //skal fjernes nå det er helt klart
currentTargetDistance = distance;
}
}
}