GUI Button no response

I been using the GUI Button when I pressed Esc button which will pause the game and shows both Retry and Main Menu button. But when I tried to click on the button, it not response to the mouse click at all.

I am using the FPS camera and control for the game. I tried to search and most result are related to GUIUtility.hotControl, but I totally no idea about it. Can someone show me how to do it or make the GUI Button work in Javascript? Thanks for the help.

function OnGUI() {
	if(paused)
	{
		if(GUI.Button(Rect(300, 50, 200, 30), "Retry"))
		{
			//Time.timeScale = 1.0f;
			//paused = false;
			Application.LoadLevel(loadLevel);
		}
		if(GUI.Button(Rect(300, 90, 200, 30), "Main Menu"))
		{
			Debug.Log("yeah");
		}
	}
}

Hi @juzajoke,

Firstly, I went to Unity Menu top
Edit → Project Settings → Input
And added 1 more Input from 17-18 (default size from the Axes)

Then I rename it:

Name of the Axes :myesc

Positive Button: escape (which is the esc keyboard)

Below is my working script:

#pragma strict
var paused : boolean = false;

function Start () {
	paused= false;
}

function Update () {
	  if(Input.GetButton("myesc"))
	  {
	  	paused = true;
	  	Debug.Log (paused);
	  }
}

function OnGUI() {
    if(paused== true)
    {
    	Debug.Log ("MENU POP UP");
		if(GUI.Button(Rect(300, 90, 200, 30), "Main Menu"))
       	{
        	 Debug.Log("yeah");
       	}
    }
}

Then I believe next step will be unpause the game.

So I added the check of pause(esc) button has pressed or not.
Just change the function update part:

function Update (){

      if(Input.GetButtonUp("myesc"))
    	  {	
    	  	if(!paused){
    	  	  paused = true;
    	  	  Debug.Log (paused);
    	  	}
    	  	else {
    	  	  paused = false;
    	  	  Debug.Log (paused);
    	  	}
    	  }
}

Please let me know if it’s working for you or not. I’m still a noob to unity. :slight_smile:

Reference:

http://docs.unity3d.com/Documentation/Manual/Input.html

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButton.html