- Home /
controlling GUI.Button state
How do I control a GUI button state?
I want to have a button that remains active until I press another button.
I don't think it's the answer....
C$$anonymous$$IIW , your code, is apparently using two different buttons right? creating another button and overwrite the previous... what I want is that to control the button like , the hover state or the active state or normal state.... Sorry if I get this wrong... :)
you're quite right, it is using two buttons. Have you tried using a GUIlayout.Toggle ?
its not a button in itself, but its got an on/off state. i'll make some links in the answer i made
Yes I did use the toggle button....But its da*n ugly...hahahaha... :)
The link is close to the answer, but it hasn't been solved either... :(
well, you can always use your own skin for the GUI:
http://unity3d.com/support/documentation/Components/class-GUISkin.html
well...I think that solved the problem... for the layout...:)
I've just got an enlightment...hahahaha still working on the scripts though. :) tq for your solution...
Answer by Kacer · Jun 27, 2011 at 08:26 AM
You can use something like this:
public class guiTest : MonoBehaviour {
public bool pressedbool = false;
void OnGUI(){
if(!pressedbool){
if(GUILayout.Button("press me to show your secrets", GUILayout.Width(400))){
pressedbool = true;
}
}else{
if(GUILayout.Button("OMG I DONT WANT TO SEE THAT", GUILayout.Width(400))){
pressedbool = false;
}
}
if(pressedbool){
pressed();
}
}
public void pressed(){
GUILayout.BeginHorizontal();
GUILayout.Label("you have pressed the first button, press the second button and this will dissapear");
GUILayout.EndHorizontal();
}
}
-Kacer
EDIT;
you can use the toggle:
http://unity3d.com/support/documentation/ScriptReference/GUILayout.Toggle.html
though, if you want unity to see if you're hovering over a gui element it becomes something else, im not quite sure on how to do it, but this link might help, there's some posts with code down the page, which seems to work, in theory at least :)
http://forum.unity3d.com/threads/6777-GUI.Button()-hover-detection