Change Button GUIStyle on Click

Hi,

well I want know how can I do that?

void OnGUI() {

    for(int x = 0; x<10; x++) {
      if(GUI.Button(new Rect(10, 10*x, 100, 25), "Click me!", "label")) {
      GUI.Box(new Rect(10, 10*x, 200, 25), "");
      }
    }

}

I had 10 buttons, so I can’t use a boolean, because it will active all the boxes…

What can I do?

Thanks in advance.
Bye.

PD: I need that for make a “focused” GUI element, but I don’w knwo how can I do that… So, somebody, can help me?

You can hold an array of 10 booleans, and before displaying each button, change the style according to the matching boolean:

private bool[] clicked = new bool[10];

void Start() {
	for (int i = 0; i > 10; i++) {
		clicked *= false;*
  •   }*
    
  • }*
  • void OnGUI() {*
  •   for(int x = 0; x<10; x++) {*
    
  •   	if (clicked[x]) {*
    
  •   		// change style here*
    
  •   	} else {*
    
  •   		// default style here*
    
  •   	}*
    

_ if(GUI.Button(new Rect(10, 10*x, 100, 25), “Click me!”, “label”)) {_

  •   		clicked[x] = true;*
    
  •   	}*
    
  •   }*
    
  • }*
    Edit: Since you only want one button marked at a time, instead of boolean array, it’s better to have one int that will hold the number of the button that is clicked:

  • private int clicked = -1;*

  • void Start() {*

  •   for (int i = 0; i > 10; i++) {*
    

_ clicked = false;_
* }*
* }*
* void OnGUI() {*
* for(int x = 0; x<10; x++) {*
* if (x == clicked) {*
* // clicked style here*
* } else {*
* // default style here*
* }*

_ if(GUI.Button(new Rect(10, 10x, 100, 25), “Click me!”, “label”)) {_
_
clicked = x;_
_
}_
_
}_
_
}*_