Game Development Reference
In-Depth Information
• Creates and assigns the CommandButton script we created earlier to the new
button
• Calls the Init function of the button (this doesn't exist yet; we will come back to
this later)
• Once everything is ready, it returns the new CommandButton game object to
whoever called it
Now we have the ability to create buttons; we will also need the ability to re-position
them within the command bar. For this, we will add another function:
void InitButtonPositions()
{
int i = 0;
float xPos = 0;
float yPos = 0;
for (int r = 0; r < buttonRows; ++r)
{
xPos = 0;
for (int c = 0; c < buttonColumns; ++c)
{
commandButtons[i].transform.localScale = new
Vector3(buttonSize, buttonSize, 0);
commandButtons[i].transform.localPosition = new
Vector3(xPos, yPos, 0);
i++;
xPos += buttonSize + buttonColumnSpacing;
}
yPos -= buttonSize + buttonRowSpacing;
}
}
This function will simply loop through all the buttons assigned to the command bar and
then scale and position them accordingly. We then have a set of arranged buttons within
the command bar according to the row and column settings we configured.
Search WWH ::




Custom Search