Construct a GUI.button like a GUI.Toggle.

Hi,

I’m not sure that I’m using the best technic at the moment.

I need to create buttons wich act like toggles. (I can’t use toggle in this case but I know how to use them).

But in general to do that I’m creating 3 GUIStyles per buttons, first one applied to the button is empty, second is button Off and third is button On (With Normal, Active and Hover used for all of them). And I’m using a bool to set the button on or button off to the active guistyle.

Is that way use perfomances ?
Is there a better, quicker way to do that ?
Should I play and set the textures to one unique GUIstyle?

Thank’s for the advises

BooBi

I would definitely recommend using a single GUI style. Look into using Compound GUIs to get the effect of a Toggle Button plus a label.

Also, if you’re going to be using a lot, you may want to just write a mini-script have each button call that (instead of clogging up your code).

So

function Toggle(curValue:bool){
if(curValue){
curValue=0;
}
else{
curValue=1;
}
return curValue;
}

Ok, I know there’s actually a simpler way to write an if/else statement. I also know I didn’t use the CODE tags. It’s 8:30am and I’m only part way into that first cup of coffee.