Pause Button (502839)

I have this script attached to a GUI Texture witch pauses the game when you click the mouse. I’m trying to set it up so you have to click on the actual GUITexture to pause and un pause the game but I’m having trouble finding the right code and I am not sure where to place it in the script. Can any body give me some pointers on this?

var paused : boolean = false;
 
function Update () {

  if(Input. GetMouseButtonDown(0))
  
  {
  
  if(!paused){
  
    Time.timeScale = 0;
   
   paused=true;
  }
  
  else{
   
   Time.timeScale = 1;
   
   paused=false;
  
  }
 
 }

}

You need to use OnGUI() for this and not mouse click.
Like this:

 function OnGUI() {
 if (GUI.Button(Rect(10,70,50,30),"Pause"))
    {
           if(paused) 
                {
                 Time.timeScale = 1.0;
                paused=false;
                 }
           if(!paused)
                { 
                        Time.timeScale = 0.0;
                         paused = true;
                }
    }
}

Much appreciated, thank you! I’m very new to Button’s… and scripting in general. When I use the script you provided I can pause the game, but it won’t un pause. I know with the if(Input. GetMouseButtonDown(0)) It toggles the pause. There a way I can apply that sort of functionality to that script?

Cuz my code is wrong. :slight_smile: change " if(!paused)" to “else” and it should work fine. (or just make it an “else if” statement)

If you want to use your code, attach it to a game object with a collider. You can make a cube and parent it to the camera in the position you want it to be visible in.

Works like a charm, thank you very much!!!