- Home /
4.6 UI, dynamic layout/resizing text lists using the text class
In the editor UI and have dynamic lists of GUI elements, like having a GameObject[] array and using a for loop to iterate through them and say, display a vertical list of thier names using GUILayout.
void OnGUI(){
foreach(Thing thing in things){
GUILayout.Label(thing.name);
}
}
how can i get a list i can populate, resulting in an automatic layout of UI.
Will i have to manually instantiate and position/setup the text object in the scene? If so, i suppose ill have to figure out positioning, of the anchor / rect, relative to screen size.
Answer by delta sniper · Oct 28, 2014 at 04:07 AM
You can add a new UIComponent to the scene where you want the text boxes to reside if you then add a "vertical layout group" component to the object all elements you add will be stacks vertically. you will also need to add a "layout element" to each of the child elements (the text elements) and set the width and height on the layout element. this will stack all the child elements so they are positioned according to the criteria on the layout elements.
For a bonus you can add another parent container and attach a "scroll rect" component to it and make the first component that has the "vertical layout group" on it as the "scroll rects" container and you can scroll you list.
Your answer
Follow this Question
Related Questions
Making a UI.Button put text into a InputField 1 Answer
Canvas Button persistence 0 Answers
Ui text to string ? 1 Answer
How do I call an DontDestroyOnLoad function on UI text 2 Answers
Get The size of the Text in unity UI 2 Answers