Accessing a particular GUI.Button in code after it has been created

I am working on a project (iOS) that requires me to have access to a particular button. I am creating several buttons using a FOR loop and using an array as its origin. Each array element has several variables that I use within the IF declaration of the button so I can give buttons functionality.

What I want to do are two things:

  1. To be able to tap a particular button and change its background without changing the background of all the other buttons. I thought of using a toggle button, but it doesn’t work for what I am trying to accomplish. I tried adding a change of GUIStyle to the IF statement but it changes all other buttons with it.

  2. I need to implement a Play functionality that basically “steps through” every button, each button changing background when it’s doing something and executing its function when it’s called.

Is there a way I can “tag” the buttons for me to access them individually later on in code? Is there a way to assign a name to a button to access it that way? Can you think of a way to achieve these things in a simpler way?

Thank you very much for the help!

I’m not sure of your exact requirements, and I’m not an expert on the GUI system since I use EZGUI for my interface word. But you can use an index to color some specific button. Here is an exmple script. Attach to an empty game object. You can change the value of indexToColor to change which button (zero based index) gets a color.

#pragma strict
 
private var indexToColor = -1;
private var rect = Rect(0,0,100,50);
private var dist = 60;
private var strings = ["One", "Two", "Three", "Four", "Five"];
private var color = Color.red;
 
function OnGUI ()  {  
    for (var i = 0; i < strings.Length; i++) {
       var r = rect;
       r.y = i * dist;
       var saveColor : Color;
       if (i == indexToColor) {
         saveColor = GUI.color;
         GUI.color = color;
       }
       if (GUI.Button(r, strings*)) {*

Debug.Log("The "+i+“th button was pressed”);
indexToColor = i;
}
if (i == indexToColor) {
GUI.color = saveColor;
}
}
}