- Home /
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?
Answer by LSPressWorks · Aug 26, 2014 at 11:39 PM
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[i].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.
ps, use a 2 or 3 dimensional array. Easier to track coordiantes I$$anonymous$$HO
Thanks! I was having one of those moments where I needed someone else to explain what I already knew. :p
Your answer
Follow this Question
Related Questions
TextMesh wordwrap 4 Answers
TextMeshPro to wordwrap on every character 1 Answer
Word Wrap forces font to revert to default settings 2 Answers
How to access planes generated by TextMesh? 1 Answer
Text Mesh + GuiTexture2D 1 Answer