I searched on Youtube and Unity Answers about the pause menu but the only problem is that the game objects of the game don’t stop and continue if it paused. I also am trying to create a pause menu once the user clicks on pause button. But, i am enable to do it. Following is my code:
using UnityEngine;
using System.Collections;
public class PauseGame : MonoBehaviour {
public GameObject Gameobject=null;
public GUISkin layer;
private Rect windowRect;
private bool paused = false , waited = true;
private void Start()
{
windowRect = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 500, 500);
}
private void waiting()
{
if (waited)
if (Input.GetMouseButtonDown(0) || Input.GetKey (KeyCode.Escape)) {
if(paused)
paused = false;
else
paused = true;
waited = false;
Invoke("waiting",0.3f);
}
}
private void OnGUI ()
{
if (paused)
windowRect = GUI.Window (0, windowRect, windowFunc, "Game Paused");
}
private void windowFunc(int id)
{
if (GUILayout.Button("Resume Game")){
paused = false;
}
if (GUILayout.Button("Restart")) {
Application.LoadLevel(4);
}
if (GUILayout.Button("Main Menu")) {
Application.LoadLevel(1);
}
if (GUILayout.Button("Exit Game")) {
Application.Quit();
}
}
}
Thanks, I would definitely try this
– Vedant_DUlori