I’m trying to size buttons on a toolbar to the size of the string on them. The strings will need to change so I can’t set them at a static number. This is the code I have which works. Is there a way of doing this with a toolbar. I just started scripting so I’m incredible new at this. Any advice is appreciated!
//C#
using UnityEngine;
using System.Collections;
public class actorGUI : MonoBehaviour
{
public Texture2D continueButton;
public GUIStyle buttonStyle;
public GUIStyle textStyle;
public int toolbarInt = 0;
public string[ ] lineOne = new string[ ] { “Button1”, “Button2”, “Button3”, “Button4”};
public string[ ] lineTwo = new string[ ] { “Button1”, “Button2”, “Button3”, “Button4” };
public string nextScene = “nextScene”;
void OnGUI()
{
toolbarInt = GUI.Toolbar(new Rect(5, 20, 600, 30), toolbarInt, lineOne, textStyle); //toolbar for first string
toolbarInt = GUI.Toolbar(new Rect(5, 50, 600, 30), toolbarInt, lineTwo, textStyle);
// Make the first button. If it is pressed, level will load
if (GUI.Button(new Rect(Screen.width - 80, Screen.height - 80, 80, 80), continueButton, buttonStyle))
{
Application.LoadLevel(nextScene);
}
}
}