Access one child of object with many duplicate names

Hello,

I’m following a tutorial where we create a cube called “brick” in the hierarchy, then we duplicate it a couple of time, we create an empty object called “row”, drag all the “brick” objects under the “row”, duplicate the rows a couple of time, create an empty object called wall and put all the rows under it.

So, my Hierarchy looks something like this :

Wall

Row

Brick
Brick

Row

Brick
Brick

Now, I make a script and I would like to access my objects from the script.
I can use GameObject.Find(“Wall”) to find my wall and it works fine. I know I could use GameObject.Find(“Wall/Row”); but what when I have multiple item called Row? Is there a way to get something like GameObject.Find(“Wall/Row[0]”)?

I thought I could use the foreach but when I write this line :

foreach( GameObject rangee in mur )

I get the following error :
error CS1579: foreach statement cannot operate on variables of type UnityEngine.GameObject' because it does not contain a definition for GetEnumerator’ or is not accessible

What am I doing wrong with the foreach?
Plus is there a way to use the GameObject.Find on objects that have the same name?

You need to use Transform instead of GameObject in your foreach, because Transform is IEnumerable and GameObject isn’t.