Get child position from last gameobject in array

I have a foreach loop that instantiates gameobjects.
What im trying to achieve is for the loop to get the position of a child in the last instantiated gameobject and update a variable according to that.

Here’s what i’ve got so far:

	foreach(GameObject seam in seams)
	{
		if (isgenerating) {
			Instantiate (seam, genlastpos, Quaternion.identity);
			genlastpos = seam.transform.GetChild (0).position;
			seamno++;
		} 
		else 
		{
			return;
		}
	}

The only problem is that i know only how to access the first gameobject.

What would be the most efficient way to do this? Thanks in advance.

Just create a GameObject var to store the “seam” you instantiated. The last loop will store the last GameObject:

private void BlaMethod()
{
       GameObject lastGO = new GameObject();
       foreach(GameObject seam in seams)
       {
             if (isgenerating) {
                 lastGO = (GameObject)Instantiate (seam, genlastpos, Quaternion.identity);  
                 seamno++;
        } 
        else 
        {
              return;
        }
     
        genlastpos = lastGO.transform.GetChild (0).position;
    }

Or inside the if statement if you need that for each “seam”.

This should work :

genlastpos = seam.transform.GetChild(seams.length -1).position;