How to get multiple array elements in Vector3.Distance?

Im programming a game and you have to you have to get close to multiple gameObjects (stool) I have put in an array. Is there a way to access them all?

  if (Vector3.Distance(holdArea.position, stool[0].transform.position) > 0.1f) {

ive tried stool[index], stool[amount], stool[0, 1, 2, 3, 4] but it wont work

One way is to use TrueForAll() from the Array class:

if (stool.Length > 0 &&   // Length must be greater 0
    System.Array.TrueForAll(stool, 
    go => Vector3.Distance(holdArea.position, go.transform.position) > 0.1f))
{
    ....
}

This method is also available in the List class.


For both variants TrueForAll() returns true if there are no elements in the Array/List, so the length should be checked or the result might be a false positive.

@dk404 Thanks it works now! ヾ(•ω•`)o