Problem with ONGUI and Buttons

So, i’m trying to make a selection menu, but I get on a LITTLE problem, to make a menu to appear/disappear I made this script:

GUI.Box(Rect(Screen.width/5,Screen.height/2*1.2,Screen.width*0.8,Screen.height*0.4),RightArrow);
	
	if(GUI.Button(Rect(Screen.width-50,Screen.height/2*1.45,50,50),WorkTex)){
	
	if(WorkGUI == false){
	WorkGUIEnable();
	}
	
	if(WorkGUI == true){
	WorkGUIDisable();
	}
}
	
	if(WorkGUI == true){
	
	if(GUI.Button(Rect(Screen.width-50,Screen.height/2*0.8,50,50),RoadTex))
	GridScript.GetComponent(GridSelectTest).prefab = Road;
	
	if(GUI.Button(Rect(Screen.width-50,Screen.height/2*1.125,50,50),RoadCurveTex))
	GridScript.GetComponent(GridSelectTest).prefab = RoadCurve;	
	}

So basicly when WorkGUI is false and I press the button it should switch to true.

It doesn’t.

But if I manually turn the WorkGUI var to true, I can switch it to false pressing the button again

what’s the problem?

You haven’t posted all the relevant code, but this part looks wrong:

    if(WorkGUI == false){
    WorkGUIEnable();
    }

    if(WorkGUI == true){
    WorkGUIDisable();
    }

I’m assuming that WorkGUIEnable sets WorkGUI to true (by the way, you should follow the convention of using lowercase for variable names and uppercase for methods and classes). If so, then you set WorkGUI to true and then immediately disable it again with the following code. So it should be

if (!WorkGUI) {
    WorkGUIEnable();
}
else {
    WorkGUIDisable();
}

–Eric

I tried the method you posted up here, It justs disable it in no time, anyway, here’s the entire code (It’s still a WIP, in fact it changed A LOT)

var Gui : GUISkin;
var PlayerCamera : Transform;
var speed = 0;
var Skin1 : GUISkin;
var Skin2 : GUISkin;
var Skin3 : GUISkin;
var Skin4 : GUISkin;
var RightArrow : Texture;
var RoadTex : Texture;
var GridScript : Transform;
var Road : Transform;
var WorkTex : Texture;
var RoadCurve : Transform;
var RoadCurveTex : Texture;
var WorkGUI = false;
var ViewTex : Texture;
var BuildTex : Texture;

function OnGUI () {

GUI.skin = Gui;
	GUI.Box(Rect(Screen.width/5,Screen.height/2*1.2,Screen.width*0.8,Screen.height*0.4),RightArrow);
	
	if(GUI.Button(Rect(Screen.width-50,Screen.height/2*1.45,50,50),WorkTex)){
	WorkGUI = true;
	}
	
	if (Input.GetButton ("Back")  WorkGUI == true){
	WorkGUI = false;
	}
	
	if(WorkGUI == true){
	
	if(GUI.Button(Rect(Screen.width-50,Screen.height/2*1.1,50,50),RoadTex)){
	GridScript.GetComponent(GridSelectTest).prefab = Road;
	WorkGUI = false;
	}
	
	if(GUI.Button(Rect(Screen.width-50,Screen.height/2*1.3,50,50),RoadCurveTex)){
	GridScript.GetComponent(GridSelectTest).prefab = RoadCurve;	
	WorkGUI = false;
	}
}

	if(GUI.Button(Rect(Screen.width/6,Screen.height/2*1.45,50,50),ViewTex)){
	GameObject.Find("Camera").GetComponent(GridSelectTest).BuildMode = false;
	}
	
	if(GUI.Button(Rect(Screen.width/6,Screen.height/2*1.3,50,50),BuildTex)){
	GameObject.Find("Camera").GetComponent(GridSelectTest).BuildMode = true;
	}
	
	GUI.skin = Skin1;
	// We provide the name of the Style we want to use as the last argument of the Control function
	if(GUI.Button(Rect(Screen.width/1-100,Screen.height/2.5,100,100),RightArrow)){
	MoveRight();
	}
	
	
	
	GUI.skin = Skin2;
	if(GUI.Button(Rect(Screen.width/8-150,Screen.height/2.5,100,100),RightArrow)){
	MoveLeft();
    }
    GUI.skin = Skin3;
	if(GUI.Button(Rect(Screen.width/2-50,Screen.height/8-100,100,100),RightArrow)){
	MoveUp();
    }
    GUI.skin = Skin4;
	if(GUI.Button(Rect(Screen.width/2-50,Screen.height/1-100,100,100),RightArrow)){
	MoveDown();
    	}
    }
	
	function MoveRight(){
	PlayerCamera.transform.Translate(Vector3.right * speed * Time.deltaTime);
	}
	
	function MoveLeft(){
	PlayerCamera.transform.Translate(Vector3.left * speed * Time.deltaTime);
	}
	
	function MoveUp(){
	PlayerCamera.transform.Translate(Vector3.forward * speed * Time.deltaTime);
	}
	function MoveDown(){
	PlayerCamera.transform.Translate(Vector3.back * speed * Time.deltaTime);
	}

Fow now I solved this problem by using the ESC Key to exit(“I’m developing for Android so it’s basicly the Back Button”) but this problem is something I really want to fix.