GameObject GetTarget()
{
GameObject TopTarget=null;
Collider[] col = Physics.OverlapSphere(transform.position, checkRadius, checkLayers);
Array.Sort(col, new DistanceComparer(transform));
foreach (Collider item in col)
{
if(item.CompareTag("HurbFood"))
{
return TopTarget;
}
else
{
Array.Clear(col, 0, 100);
}
}
Target = TopTarget;
return Target;
}
in this i have sorted a array of colliders based on distance and i am trying to assign the target closest for my AI to move to.
i need to eventually add other conditions based on the Object tag that the collider will encounter but i need to know the target will be assigned first.