Hi guys, before asking my question i searched for about an hour over internet and i didnt find any explanation of what is happening to my list. Here’s what i want to do : I want to sort my ennemies by their distance to my tower ( tower defense ). It works pretty well, my only problem is that my tower always attack the furthest of the list. Thanks if you can help me ! Thanks anyway if you cant !
if(targets.Count > 0)
{
targets.Sort(delegate(Transform t1, Transform t2)
{
return Vector3.Distance(t1.position, transform.position)
.CompareTo(Vector3.Distance(t2.position, transform.position));
}
);
closestEnemy = targets[0];