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.

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 :slight_smile:

http://forum.unity3d.com/threads/6777-GUI.Button()-hover-detection