(4.6 UI) How to set up a window with x buttons, with a scroll bar?

Hi! I’ve been playing around with the 4.6 beta, but I’ve been having a hard time figuring things out… For part of my UI, I want to have a window that, depending on how many objects is in an array, makes buttons (one button per object in the array), and has a scroll bar if the list of buttons won’t fit in the window.


How do you create a button in the script?

I’m assuming I can detect when to enable/disable the scroll bar by checking (button height * number of buttons), but how do I make it scroll down through the list of buttons?

What should I use for the window to hold it all, a Panel?

Any other tips/tricks/suggestions? Thanks for your help

I think it’s best to create a prefab for the button and then instantiate it, instead of trying to create it completely in script.

As for scrolling there is a Scroll Rect component, which you can combine with a Mask (so items are not visible outside the scroll area) and there is also a scroll bar object and component.

You can place you buttons under a parent with a vertical / horizontal layout group component and use layout element component on the button to control how they arrange and fit in the list.