- Home /
Question by
Jean-Fabre · Nov 02, 2010 at 06:07 AM ·
guiguilayoutcenter
How to center gui element within a beginVertical section?
Hi,
Struggling to find a way to center elements horizontaly within a vertical section. Either I missed a very obvious set up or else it needs some rect computation, but can not find anything that sparks a solution in my head for this just yet.
GUILayout.BeginVertical();
GUILayout.Button("Click here",GUILayout.Width(100));
GUILayout.EndVertical();
Thanks for your help,
Jean
Comment
Best Answer
Answer by Mike 3 · Nov 02, 2010 at 09:28 AM
You could abuse a horizontal section for it with flexible space either side:
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Button("Click here",GUILayout.Width(100));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
The only problem is that you'd have to have the horizontal section for each item inside the vertical block
Your answer
![](https://koobas.hobune.stream/wayback/20220613081653im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUILayout formatting help 1 Answer
GUILayout Textfield not editable just static 1 Answer
Using treeview OnGUI with GUIlayout 0 Answers
How to change thickness of ScrollBar of GUILayout ScrollView? 0 Answers
Open gui if player clicks on button 2 Answers