Accessing Multiple Buttons Made via For Loop

I’m currently trying to make a menu of sorts where there are numerous buttons created through a for loop depending on how many options there are.

This is for a Battle UI, when the character whose turn it is selects either the White or Black Magic list, it is to populate a GUI Group with a series of systematically laid out buttons for the user to choose from.

The issue I’m having right now, is I can’t seem to find a way to single out each button to press.

I’m creating the buttons like this:

for(int i = 0; i <battleGUI_.activeParty[battleGUI_.playerTurnCount].GetComponentInChildren<Characters>().magic_[0].Count; ++i)
 {
    if (GUI.Button(spellRectPositions_<em>, battleGUI_.activeParty[battleGUI_.playerTurnCount].GetComponentInChildren<Characters>().magic_[0]*.name))*</em>

{

}
}
I haven’t been able to think of a way to access them individually, so that you can click on the one with named Fire and have it cast Fire on the enemy, but instead if I do it in the for loop, it will cast wherever it is in the for loop at the time (as to be expected).
Does anyone have an idea as to how I can single out the buttons without changing my for loop into a bunch of if() statements?
Note: I did neglect to mention that this is in 2D
Edit: Spell casting implementation as requested:
battleGUI_.selectedBoss.GetComponentInChildren().CalculateDamageTaken(battleGUI_.activeParty[battleGUI_.playerTurnCount].GetComponentInChildren().magic_[0].effectivity, “Magical”, 1000);
Debug.Log("Casted " + battleGUI_.activeParty[battleGUI_.playerTurnCount].GetComponentInChildren().magic_[0][1].name);
battleGUI_.playerTurnCount++;
battleGUI_.GetComponent().PlayerHasAttacked = true;

You could use an array of delegates for your button to call from.

delegate int CastSpell();
CastSpell[] castSpells = newCastSpell[10];

//Assign the delegates to methods in Awake

 for(int i = 0; i <battleGUI_.activeParty[battleGUI_.playerTurnCount].GetComponentInChildren<Characters>().magic_[0].Count; ++i)
  {
     if (GUI.Button(spellRectPositions_<em>, battleGUI_.activeParty[battleGUI_.playerTurnCount].GetComponentInChildren<Characters>().magic_[0]*.name))*</em>

{
castSpells*();*
}
}
However reading your code again you are probably better having a specific class to store each spells in, and using polymorphism to call a method on that.

This may not be practical depending on how much work you’ve already sunk into your UI, but what you want to do would likely be much easier with the new 4.6 uGUI stuff. I never found that the old stuff worked all that well with non-basic operations.

eg. This in your for loop:

Button button = buttonObject.GetComponent<Button>();

button.onClick.AddListener(delegate {
            Debug.Log("Casting spell " + magic_[0]*.name);*

});
Then combine this with a delegate array as mentioned or some other form of polymorphic argument.