accessing gameobjects in hierarchy in specific order via arrays

HI guys,

I have a fairly simple problem (except for me)…I have created an array of card hands, and I want to access their names through an array in the order as appears in the hierchy:

For example, in the hierarchy it shows:

Canvas

Hand

card1
card2
card3
card4

I have created this code:

players = GameObject.FindGameObjectsWithTag(“Player”);

    foreach (GameObject x in players)
    {
        Debug.Log("Player  " + x+ " is named " + x.name);
    }

I can access the card hands but the order is wrong. ANy suggestions ?

Thanks

Marlon

I guess card1 to card4 are children of Hand and Hand has the Player-Tag? You could do the following:

for (int i = 0; i < Hand.transform.childCount; i++){
  var cardfromTopToBottom = Hand.transform.GetChild(i);
  // do stuff with cardFromTopToBottom
}

Hex,

You’re a f-ing GENIUS ! Works like a charm ! Thanks very much man …really appreciate it !