- Home /
Wrong Scene loading from Pause
When I am in Pause state, and click on the Resume to Level button, instead of it going to the game, it goes to the main menu. No matter what number I type in the parentheses. The code and picture follows: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class PauseGame : MonoBehaviour { public bool gamePaused = false; public AudioSource levelMusic; public GameObject pauseMenu; public AudioSource pauseJingle;
void Update()
{
if (Input.GetButtonDown("Cancel"))
{
if(gamePaused == false)
{
pauseJingle.Play();
Time.timeScale = 0;
gamePaused = true;
Cursor.visible = true;
levelMusic.Pause();
pauseMenu.SetActive(true);
}
else
{
pauseMenu.SetActive(false);
levelMusic.UnPause();
Cursor.visible = false;
gamePaused = false;
Time.timeScale = 1;
}
}
}
public void ResumeGame()
{
pauseMenu.SetActive(false);
levelMusic.UnPause();
Cursor.visible = false;
gamePaused = false;
Time.timeScale = 1;
}
public void RestartLevel()
{
pauseMenu.SetActive(false);
levelMusic.UnPause();
Cursor.visible = false;
gamePaused = false;
Time.timeScale = 1;
SceneManager.LoadScene(3);![alt text][1]
[1]: /storage/temp/189959-pause.jpg
Thank ou CodesCove
When the game is paused I have three links or buttons as shown on this attached picture.
In the inspector you can see how the RestartLevel () function is called from the script on the attached picture which apparently refuses to upload for you to see
Since this will not allow me to upload a second picture I can be reached by e-mail at josephripley69@gmail.com
Instead of using simply 3, try using SceneManager.GetActiveScene().buildIndex?
Add Debug.Log("Scene Path: " + SceneUtility.GetScenePathByBuildIndex(3));
to the RestartLevel() function before the LoadScene and check what is written in the Console window.
if nothing is written then it's not actually called. Otherwise you get info about what scene is actually loaded.
PS. You should be able to add more that one image here.
Your answer
Follow this Question
Related Questions
Resume Button Sound Not Playing 1 Answer
Basic question about creating a menu 1 Answer
Touch button to load scene, instead of touching anywhere on screen 1 Answer
Build resolution errors 0 Answers
Clicking Trigger 1 Answer