I'm creating some player buttons dynamically, and have that part down pat. I've got a UISprite object that will host the buttons created.
I want the first button to align to 20px of the left and -20 px of the top of the ButtonHost object, but I want the button to keep it's width and height, so not anchor to the right/bottom of the parent.
Then, if this is a subsequent button, it needs to align to the previous one (which works correctly).
My code is:
if (Players.Count == 0) {
// We have to set the anchor to the listGridRoot
PlayerButtonSprite.SetAnchor(ButtonHost, 20, 20, -20, -20);
} else {
// we have to set the anchor to the previous player button
GameObject PreviousPlayerButton = Players [Players.Count - 1].Button;
PlayerButtonSprite.SetAnchor(PreviousPlayerButton, 0, -50, 0, -50);
}
As a follow-on, how would I expand the ButtonHost item to surround all of the created buttons?