Hi,
Simply for convenience, I am trying to create a static method that returns the closest transform in a passed array. Is it possible to read components off of a generic array?
public static Transform FindClosestInArray <T>(T[] array, Vector2 origin)
{
Transform nearest = null;
float minDist = Mathf.Infinity;
//loop through all to find nearest
for(int i=0; i<array.Length;i++)
{
float dist = Vector2.Distance(array*.transform.position, origin);*
if(dist < minDist)
{
nearest = array*.transform;*
minDist = dist;
}
}
return nearest;
}
edit: Thanks everyone for the assistance!