Can I dynamically create buttons from an arraylist?

In my program I am trying to create buttons from an arraylist; however, I can’t seem to get it working. The button is displayed with the correct name whenever I add something to the arraylist useroptions, but whenever I click on the button the action that I define in the curly braces is not triggered. I have the following code in my OnGUI function:

foreach (string s in userOptions)
        {
            Debug.Log(s);
            if (GUI.Button(new Rect(100, 100, 300, 300), s))
            {
                Debug.Log ("HERE");
                npcConversation.reponseText = s;

            }
        }

I ran a quick test of your code. It appears to work fine (other than you are placing all the buttons on top of each other). Here is what I did:

using UnityEngine;
using System.Collections;
 
public class Bug20 : MonoBehaviour
{   
	string[] userOptions = new string[] {"one", "two", "three"};
    void OnGUI ()
    {
		foreach (string s in userOptions)
	        {
	            Debug.Log(s);
	            if (GUI.Button(new Rect(100, 100, 300, 300), s))
	            {
	                Debug.Log (s);
	            }
	        }
    }
}

If I click on the button, it outputs text for all three buttons (which I did not expect).