Okay, I’m still relatively new to Unity3d and trying to figure out the best way to do certain things with it.
For instance for buttons there seems to be multiple different approaches. I’m currently trying to generate a set of buttons dynamically that would be used to control the player’s character. Dynamic approach is necessary as the set of available commands is rather fluid.
I would essentially like to have them in three columns on the left side of the screen.
I managed to create the buttons, but am struggling with adding images to them. I have a spritesheet with several different button types and states inside it, but GUIlayout.Button doesn’t seem to want to have anything to do with them.
I tried converting sprites to textures, but Unity seems to add image of the whole spritesheet into the button instead of a single sliced image from within the sheet.
Anyways. To sum up my questions.
- How would I go about making several vertical columns instead of single long one?
- for the texture issue, do I have to cut the buttons I want to use from the spritesheet myself, outside unity?
Here’s also my current code, I’m sure there are smarter ways to do these things. Please feel free to tell me how
GUILayout.BeginArea(new Rect(15, 15, 200, 600));
GUILayout.BeginVertical();
btnHeight = 40;
btnWidth = 40;
for (int i = 0; i < movesAvailable.Length; i++)
{
GameObject gobj = Resources.Load("MainGame/GUI/buttons/" + movesAvailable*) as GameObject;*
SpriteRenderer rend = gobj.GetComponent();
Sprite sprite = rend.sprite;
GUILayout.Button(sprite.texture,“button”, new GUILayoutOption[] { GUILayout.Width(btnHeight), GUILayout.Height(btnWidth) });
}
GUILayout.EndVertical();
Cheers!