Instantiate and create a list of objects evenly

I instantiate a set of objects with TextMeshes and I run a WordWrap function. So I have a series of text objects of varying heights. Assuming that I have the height value for each text mesh what would be my method of sorting this objects beneath each other at an even distance?

heightValue + space

So if box one is at 35 px y+

         35px    12px         2px

Box2.y = (box1.y + box1.height + space);

OR by using a for statement with the array length, it’s no parenthesis in unity btw…

           35px         12px       2px

box*.y = (box[i-1].y + box[i-1].height + space);*
Where the second method is preferred since it can handle a wider range of input, literally any number of elements inside the array.
is your coordinate method center or 0x,0x based?
if it is center based, you probably have to multiple the space by number of elements in your initial array or vector.
now if you’re asking how to sort them like, alphabetically you need to load their values into an array, pop(bubble) sort the values, then apply those values.