- Home /
How to reset the state of other buttons when clicking on one of them
Hi all. I'm working on an application in which i can pick a colour by clicking on buttons. Only one colour can be picked at the time. When picking, the texture of the button has to change. So I'm currently trying to set a list of buttons. For each one, i've got 2 different textures (for on and off state). I first tried with GUITextures, but as each button is independant, i can't figure out how to reset the other buttons states... So i tried with a buttonlist. Now the buttons are created through the script and i'm not able to change their texture when clicking on it. I've changed them for toggles, with no more results.
My big problem is that each button has to use specific textures, and I don't understand how tu use GUIskins. I've found this post that helped me, but doesn't work as I expected (can't change the button texture on click) Here's my actual code, hope i was clear and someone can help me :)
var Texture : Texture2D;
var TextureClic : Texture2D;
var position : Rect;
var isSelected : boolean; // is the toggle button on or off
var buttonList : ButtonChange_onclick [];
function OnGUI(){
for ( var i = 0; i < buttonList.length; i ++ ) {
var butt = buttonList[i];
butt.isSelected = GUI.Toggle(position, isSelected, "button");
GUI.DrawTexture(position, Texture);
if ( butt.isSelected ){
print("This butt is turned on: ");
resetOtherButtons(i);
}
}
}
function resetOtherButtons ( ignoreThisNumber ) {
for ( var i = 0; i < buttonList.length; i ++ ) {
if ( i != ignoreThisNumber ) {
buttonList[i].isSelected = false;
}
}
}
Also, why can't the buttonList be set automatically by looking for all the buttons with that script applied ? Note : With that code, the text "This butt is turned on" is displayed, but the boolean isSelected is always set to "false".