How to Name Individual Buttons Within a List

Hi everyone, I have been trying to figure out a way to name all of my buttons that are within a list individually. I can’t quite figure out how to do that. If I try to put text.ToString() within the GUIlayout.button function I get this error GUIlayout.button has invalid arguments.

    public List<int> listOfButtons = new List<int>();
    public string[] Text;
    void OnGUI(){
    Text = new string[]{"Button1","Button2","Button3"};
    for (int i = 0; i < listOfButtons.Count; i++)
    GUILayout.Button(Text.ToString());//Error GUILayout.Button has invaild arguments
    }

There are two issues with your code:

  1. “listOfButtons” is empty, so iterating over it won’t generate any UI buttons.
  2. When grabbing the text for each button, you would need to index into the array.

Here’s the updated code:

    public string[] Text;
    void OnGUI()
	{
	    Text = new string[]{"Button1","Button2","Button3"};
	    for (int i = 0; i < Text.Length; i++)
		{
	    	GUILayout.Button(Text*);*
  •  }*
    

}

You might have to create a new data type to hold the information that you need. For instance: (written on the fly)

public class myButton
{
    public string text;
    //now put the functions you need for clicking
}
//Make sure to fill this :P
public List<myButton> listOfButtons = new List<myButton>();
void OnGui()
{
   for (int i = 0; i < listOfButtons.Count; i++)
        if(GUILayout.Button(listOfButtons_.text) )listOfButtons*.OnClick();*_

//You can have different functions called for different buttons
}
Of course that all could be unnecessary and you might just need to use a Hashtable. Can you give some more information on the specifications needed for this project?
Thanks! :3