I have a pause menu script with three buttons, resume main menu and exit, but I have a problem when I make main menu and reload the same level or another scene, I stop the scene, I have to pause and click resume , to make it unlock. Where is it that you can solve in the script or do I have to do anything else? If you need to do another script or something to load the scenes, can someone do it to me or explain it in a simple and clear way maybe with a short tutorial? Thanks for your patience.
This is the pause menu code:
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using UnityEngine.UI; //Need this for calling UI scripts
public class Manager : MonoBehaviour {
[SerializeField]
Transform UIPanel; //Will assign our panel to this variable so we can enable/disable it
[SerializeField]
Text timeText; //Will assign our Time Text to this variable so we can modify the text it displays.
bool isPaused; //Used to determine paused state
void Start ()
{
UIPanel.gameObject.SetActive(false); //make sure our pause menu is disabled when scene starts
isPaused = false; //make sure isPaused is always false when our scene opens
}
void Update ()
{
//If player presses escape and game is not paused. Pause game. If game is paused and player presses escape, unpause.
if(Input.GetKeyDown(KeyCode.Escape) && !isPaused)
Pause();
else if(Input.GetKeyDown(KeyCode.Escape) && isPaused)
UnPause();
}
public void Pause()
{
isPaused = true;
UIPanel.gameObject.SetActive(true); //turn on the pause menu
Time.timeScale = 0f; //pause the game
}
public void UnPause()
{
isPaused = false;
UIPanel.gameObject.SetActive(false); //turn off pause menu
Time.timeScale = 1f; //resume game
}
public void QuitGame()
{
Application.Quit();
}
public void Restart()
{
SceneManager.LoadScene(1);
}
public void Resume()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
timeScale is static, so if you set it to 0f in a pause menu, then when switching scenes, you’ll want to reset it back to 1f, or else it will still be 0f.
If the timescale is 0 and you have code that depends on timescale, you will need to reset it back to 1f before you switch scenes. You can leave it at 0f for your pause if that covers the pausing of the game.
The problem is that when I go back to the scene, which I wanted to do with the main menu pause menu, example from the number 3 which is the level, to build number 1 which is the main menu, does not load the scene, remains locked. … I do not know how to solve it. Could you fix it yourself?
Just try resetting timescale back to 1f before you switch scenes. You should be able to do it before the loadscene calls. If this doesn’t work, let me know, but I think it should fix it.
Sure, I could fix it, but like anything, you have to go through debugging steps to solve problems.
I mostly work on one-scene projects so I don’t know much(but I know I love you)
Maybe try setting time scale back to 1 on the start of your restart/menu methods?
I know maybe to do crazy, but I could pass my project, so you see the problem and I settle it, I would also like to put an online system a royal battle where your ball has to throw down more enemies “online opponents” before time runs out, the one who threw it the most down the coins wins, which will serve to unlock various buttons on the menu and the coins are the same that you collect in the various levels of the story. My player is a rollerball,
If you do I’ll put you among the acknowledgments of my game, and if you want I’ll pay you. My game is also found on the android playstore, but I can not solve those problems there.
Is the only issue you have is the changing scenes? If that’s it, I could take a glance, but if it’s much more than that, I probably don’t have time to look into it honestly.
It is the change of scene, I can not solve it for me is a drama. Then I would also like a script or something that collects a number of coins in the various levels “scene” will unlock buttons in the menu. But I can not save them because I think I need something like gamemanager or playerprefab I read on the internet that are used to save the progress of the game, but I do not know how to create it. Scripts do not create them from scratch, I would like you to help me create them for these things. Thank you so much for your help:)
i said may be i can , but its seems , may be guy drooped the project, or he got solved it , and forgot to update , by the way who is waiting 2 years to solve such issue ,May be he become pro in programming , i know just basic stuffs at least guy should give some response !
I know this is a old post but for people who stumble across this who need help.
The reason why the next scene is paused is because the time scale stays the same until updated across any scene. To fix this there’s two ways. You can type Time.timeScale = 1; in the function where you exit the scene however. It will continue for a split second and we don’t want that. You want to type Time.timeScale = 1; on your main menu scene or the next scene in the void Start() Method. Hopefully this helps and apologies for the long reply.