0

I'm not familiar with Unity's new UI system of 4.6 and later. I would like to display a series of buttons on screen and have them center-aligned and breaks into the next line when screen width is reached. The old OnGUI function no longer seem working so I wonder how can I achieve this?

Max Yankov
  • 12,551
  • 12
  • 67
  • 135
Yangrui
  • 1,217
  • 2
  • 17
  • 41

1 Answers1

3

You need to use UI's layout system. Usually, you just create a Layout Group and populate it with objects that have Layout Element component.

Max Yankov
  • 12,551
  • 12
  • 67
  • 135
  • I added the grid layout group but when the line startes all elements are left aligned. Can I make them centered? – Yangrui May 04 '15 at 03:39
  • Have you tried changing the `Child alignment` property of the `Layout Group` component? – Max Yankov May 04 '15 at 07:50
  • The child alignment positions all buttons as a whole, how can I make each line horizontally centered? – Yangrui May 04 '15 at 21:09
  • 1
    Solution found! A community plugin called FlowLayoutGropus works perfectly, though Unity should officially include theses functions. Here's download link: https://bitbucket.org/ddreaper/unity-ui-extensions thanks for pointing me out Layout Group – Yangrui May 05 '15 at 03:53