Clearing a GUI and Pausing a Game

So i want to make that when first i move to this Scene, the game is paused. Until i press Start button, and all GUI cleared, and the game play again…
I’ve been searching all over the Answer section, yes i get a lot of good answer, but i can’t done it…

So basically this is as far as i could do, and understand…

var images : Texture2D[];//5 images
var i : int;
function OnGUI () {

	Time.timeScale= 0;
	//fungsi untuk slide tutorial next dan previous
	GUI.DrawTexture(Rect(200,50,100,100), images*);*
  • if(GUI.Button(new Rect(210,300,100,50),“next texture”)){*
  •  i++;*
    
  •  if(i>images.Length-1){i=4;}*
    

_ GUI.DrawTexture(Rect(200,50,100,100), images*); _
_
print(i);_
_
}_
_
if(GUI.Button(new Rect(100,300,100,50),“previous texture”)){_
_
i–;_
_
if(i<images.Length - 5){i=0;}_
_ GUI.DrawTexture(Rect(200,50,100,100), images);
print(i);
}
if(GUI.Button(new Rect(400,400,50,50),“Start”)){
//erase all GUI, but don’t know how to do it*
* Time.timeScale=1.0;
}
}*
i think using Time.timeScale is the best and easiest way(is that true?) to pause the game… but when i press “Start” button, the time didn’t go back to play… i mean, anything still stop … is there anyway to achieve this?_

Time.timeScale is a fine way of pausing the game. The issue you’re having is that you’re setting Time.timeScale to 0 every single call of OnGUI. You want to set it to 0 after a certain event. For example:

void Update()
{
    if ( Input.GetKeyDown( KeyCode.Escape ) )
    {
        Time.timeScale = 0;
    }
}

void OnGUI()
{
    if ( Time.timeScale == 0 )
    {
        if ( GUI.Button( new Rect( 400, 400, 50, 50 ), "Start" ) )
            Time.timeScale = 1.0;
    }
}

This will check if you press escape and when you do, will show the gui to unpause it. Hope this helps to lead you in the right direction!

If you want the game to start paused you could move the code in Update() to your Start() function like this.

void Start()
{
    Time.timeScale = 0;
}

void OnGUI()
{
    if ( Time.timeScale == 0 )
    {
        if ( GUI.Button( new Rect( 400, 400, 50, 50 ), "Start" ) )
            Time.timeScale = 1.0;
    }
}