Pause Scene on buttonclick

I’m working on an Android game right now, it’s almost done and i want a button to pause the game and open a menu of options (sound of off, back to menu, quit game).

As always i don’t have a clue how to do this… I’m thankfull for every answer!

I would make menu using new UI system. Same for this button to pause game. This “Open Menu” button would have button component and its On Click method. Maybe in GameController script you could add public method to toggle open/close menu something like this:

private bool _isOpened; // is menu opened?

void Start() {

    _isOpened = false;
}

public void ToggleMenu() {

    if(_isOpened)
        CloseMenu();
    else
        OpenMenu();
     
    _isOpened = !_isOpened;
}

Also, CloseMenu() would contain Time.timeScale = 1 and OpenMenu() Time.timeScale = 0. And would turn on/off GUI components. You can group them in Canvas GameObject. E.g. “Main Menu” that would be child of Canvas and had 3 GUI Texts "Sound ", “Back to Menu”, “Quit Game”. And again all of them would have button component to do actions.

Hi,

there are different ways to do it.
If you use a slide in / out animation, i recomment 2 scripts.

First the UI handler which handles all animations. Put that on any GameObject in your scene.

using UnityEngine;
using System.Collections;

public class UI_Manager : MonoBehaviour {

	public void DisableBoolInAnimator(Animator anim)
	{
		anim.SetBool ("IsDisplayed", false);
	}

	public void EnableBoolInAnimator(Animator anim)
	{
		anim.SetBool ("IsDisplayed", true);
	}
}

Now just give your button the access enable…

You can then use a options script or put that stuff also in the UI Handler

public void PauseGame()
	{
	     Time.timeScale = 0;
	}

	public void UnpauseGame()
	{
	     Time.timeScale = 1;
	}

When use sliding menus make sure you call pauseGame() after the animation ended by using event system in the animation window.

Hope it helps.

Thank you guys for your suggestions and help, my script is working now!