- Home /
Pause Menu Messes Up Game
In my game I have a pause menu. I also have a button that makes the pause menu pop up. The pasue menu has buttons to resume the game and quit. I have a spawner that spawns a prefab. To make the spawner work I have a transparent button the size of the entire scene. When I click this button to make the ball spawn, the entire game stops.
Spawn Ball: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class BallSpawn : MonoBehaviour { public GameObject Ball;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update () {
}
public void Yep () {
Instantiate (Ball, transform.position, Quaternion.identity);
}
}
Pause Menu: using UnityEngine.SceneManagement;
public class PauseControllerScript : MonoBehaviour {
public string mainMenu;
public bool isPaused;
public GameObject pauseMenuCanvas;
public GameObject button;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update () {
if (isPaused) {
pauseMenuCanvas.SetActive (true);
Time.timeScale = 0f;
} else {
pauseMenuCanvas.SetActive (false);
Time.timeScale = 1f;
}
}
public void Resume () {
isPaused = false;
}
public void Quit () {
SceneManager.LoadScene ("StartScreen");
}
public void PauseMenuOpen () {
isPaused = true;
button.SetActive (false);
}
}
The pause button works though ;-)
Answer by eskivor · Jul 22, 2017 at 12:42 AM
check that your Time.timeScale
is still equal to 1 (use a Debug.Log ();
for that in your Update
)
PS : you don't have to check the pause state in the Update
at every frame, do it only when you active the pause and when you resume the game, nothing more.
Ok I did the debug thing and it didn't pop up but everything else in the game stopped.