I need to find the closest object with the tag “enemy”. I placed them in an array and calculated the distance of them. But i cannot figure out how to sort them and get the lowest of them.
public GameObject[] Enemys;
void Awake()
{
Enemys = GameObject.FindGameObjectsWithTag("Enemy");
}
void Update()
{
if (Input.GetKeyDown(KeyCode.I))
Sort();
}
void Sort()
{
foreach (GameObject E in Enemys)
{
float dis = Vector3.Distance(this.transform.position, E.transform.position);
Array.Sort(dis); //HERE HELP
Debug.Log(dis);
}
}