button with own will!

Hi there guys

I want to let my right mouse button switch a GUI on and off, but I just can’t get it to fire only once when I press the button!

Thanks

function OnGUI () {

if(Input.GetButton("Fire2"))
{
	if(isScopeOpen == "false")
		{
			isScopeOpen = "true";
		}
	else
		{
			isScopeOpen = "false";
		}
	
}
	
	if(isScopeOpen == "true")
	{
	// Make a group on the center of the screen
	GUI.BeginGroup (Rect (Screen.width / 2 - 512, Screen.height / 2 - 384, 1024, 768));
	// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.

	// We'll make a box so you can see where the group is on-screen.
	GUI.Box (Rect(0,0,1024,768),GUIContent(scopeBg));
	//GUI.Box (Rect (0,0,100,100), "Group is here");
	//GUI.Button (Rect (10,40,80,30), "Click me");

	// End the group we started above. This is very important to remember!
	GUI.EndGroup ();
	}
}

use getbuttondown instead of getbutton :stuck_out_tongue:

Thanks, but for some reason it change the value to true, but then skips over to the else section and make the value false again. It basically execute the whole if block of code twice, which result in the GUI being added and removed so fast that you can’t even see it…

Either add a pause, or wait until you getbuttonup event, before you will toggle it again :slight_smile:

Sorry, can you maybe give some code hint or something, I’m a bit stumped with this one:)