Hi all,
I am making a list of commands using a Class Array containing the Command itself, the Description of the Command and the Button that can be used to activate said command, however I am having trouble trying to find a way to transfer the Buttons information when the button is clicked.

As you can see above the UI containing the Command, Description and Button is a prefab that is Instantiated per Command in the below Photo, therefor I cannot manually attach a Script to the Buttons On Click () function.
The code I am using to update this information is:
void startupProcess()
{
while (currentAddedCommands < cmds.Length)
{
GameObject temp = Instantiate(commandPrefab, commandSpawnPos);
temp.transform.GetChild(0).GetComponent<Text>().text = cmds[currentAddedCommands].command;
temp.transform.GetChild(1).GetComponent<Text>().text = cmds[currentAddedCommands].description;
cmds[currentAddedCommands].btn = temp.GetComponent<Button>();
cmds[currentAddedCommands].btn.onClick.AddListener(activateCommandBtn);
currentAddedCommands++;
}
}
void activateCommandBtn()
{
}
But after that I am just completely lost on how to actually reference the button that was pressed so the correct Command can be activated.
Should I just create another script that is attached to the Instantiated UI Panel that handles the click event and then that script can send the clicked data over to the testingEnhancer.cs Script? The only downside to this is it somewhat adds yet another thing to do each time I add a new command to the game is rather than just adding the command to the testingEnhancer Script I will then also have to create a unique ID for each button so the script knows which command needs to be activated. I am at that stage in my game where I am cutting back on the amount of things that I need to do when implementing things much like this command system as I know for a fact new commands will be added later, so I am putting in the hard work now to make it as easy as possible for me to add new commands without having to go through 20 other objects/scripts and also update them to accommodate the new command per se.
As it currently stands, Commands that are added to the Cmds Class Array instantiates a UI Prefab per command, sets the Title of the Command and Sets the Description, without having to modify or adjust anything else it is all done automatically by the script - however I want to add the ability for players to be able to Click the command on the list to activate it rather than having to manually type it. It’s easy to send Information from a button that is not instantiated as you could easily just Drag your script onto the On Click () event add an ID that would represent the Command within the Arrays ID activating that specific command, but how to actually set/carry information when a button is instantiated just seems to be so taboo and there seems to be no way to do this "Drag Script, Assign ID) via script it seems to only be allowed in the hierarchy, or even just how to reference the button that was clicked seems so difficult and any amount of Google Searching and Unity Scripting API does not answer my question… If I could find a way to reference the button that was clicked, I could simply just get the Text component (attached to the Child(0) of the Button Component) which is the title (the exact string to activate the command) and tell the testingEnhancer script to activate that command, but without knowing what button was pressed, there seems to be no way to carry information from an Instantiated Button in an automated fashion without manually marking each button with an ID which again makes it annoying when later adding new commands as I generally forget about those extra little nit picky things and not only that its annoying when you want to add "1 simple thing’ to your game but to add that one thing you’ve got to change/adjust 20 other things just to make it work.
I hope I have explained my situation enough as I remember I have asked this question quite a while back and never got a response, which again adds to my frustration of Button Events via script just seems so Taboo and Unknown in the Unity Community and Scripting API the only way I’ve found is by adding a Listener to the button on the Start-up Process though this seems to revoke the ability to be able to ID or Reference the specific button that was clicked thus not knowing which command needs to be activated when the button is clicked.
Any help would be greatly appreciated, I have been playing around with this the last few days and just haven’t gotten anywhere closer and any research about this just leaves me more confused