Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Unidesky · May 03, 2020 at 10:48 PM · scripting problempause menurestart game

Game doesn't start after death and pause menu

Hello, i've been working on a game for Android devices which includes a death and respawn system from a tutorial on youtube, the problem is after death i must press Esc to make the menu appear and after clicking on the Restart option it doesn't start until i press Esc again. Any help with that?

Manager script: public class Manager : MonoBehaviour { bool gameHasEnded = false;

 public float restartDelay = 1f;

 public void EndGame()
 {
     if(gameHasEnded == false && Lives.livesCounter == 0)
     {
         gameHasEnded = true;
         Invoke("Restart", restartDelay);
     }
 }

 void Restart()
 {
     SceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }

}

Pause menu script: public class PauseMenu : MonoBehaviour { public static bool gameIsPaused = false;

 public GameObject pauseMenuUI;

 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         if (gameIsPaused)
         {
             Resume();
         } 
         else
         {
             Pause();
         }
     }
 }

 public void Resume ()
 {
     pauseMenuUI.SetActive(false);
     Time.timeScale = 1f;
     gameIsPaused = false;
 }

 public void Pause ()
 {
     pauseMenuUI.SetActive(true);
     Time.timeScale = 0f;
     gameIsPaused = true;
 }

}

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shadowpuppet · May 03, 2020 at 11:04 PM 0
Share

Just a guess, but do you need to make gameHasEnded =false; again , maybe in the Restart(), or does that reset to false upon the game restarting? By hitting the escape the first time to get the menu to appear you are pausing the game so maybe thats why button doesn't work? and hitting it a second time to unpause it. Shouldn't pause$$anonymous$$enuUI.SetActive(true) appear automatically in the Restart()?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ZachCreates · May 03, 2020 at 11:16 PM

I may be wrong, but I believe your problem is caused by you setting Time.timeScale to 0. Since you did that, your restartDelay timer will never go down in time. The reason you need to press esc again is because when you do that, time starts up again. Do you need a restartDelay? If you took that out, it would be fine I believe.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Unidesky · May 03, 2020 at 11:56 PM 0
Share

I took the restartDelay and replaced it with Restart(); to summon the function but it does the same. It also keeps summoning prefabs like it isn't paused after death which i thought i made possible in another script:

public class $$anonymous$$anager : $$anonymous$$onoBehaviour { bool gameHasEnded = false;

 public void EndGame()
 {
     if(gameHasEnded == false && Lives.livesCounter == 0)
     {
         gameHasEnded = true;
         Restart();
     }
 }

 public void Restart()
 {
     Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name);
 }

}

avatar image ZachCreates Unidesky · May 04, 2020 at 01:27 PM 0
Share

I’m not exactly sure what is happening here, but you could try debugging a little. Try adding these:

void Update() { Debug.Log(Time.timeScale); //Try debugging other things too! }

I’m sorry I couldn’t find the problem, but I hope that this helps!

avatar image Unidesky ZachCreates · May 16, 2020 at 10:25 PM 0
Share

Sorry for the delay, i've been busy with home office. I made a gif of the process i am having problems with:

https://imgur.com/a/5Z6Ydv0

I was using a website for gif edition and it have it's problems but i hope my problem can be understood. In less words when i die in game i need to press Esc, time keeps going, to show the restart menu, then click on restart to being again but i need to press Esc again to begin because for some reason the time remains in 0.

avatar image ZachCreates · May 18, 2020 at 02:22 AM 0
Share

I’m not sure exactly what the issue is here. I think that it has something to do with changing the timeScale, but I don’t know. I have an alternative option that might work.

You could try making the restart function public, then putting the script as a component of the restart button, and finally linking the button being clicked to the restart function.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

300 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with pause menu and cursor lock script conflict 1 Answer

hey im trying to make a pause menu, it keeps poping up at the start and i have no idea how to fix. 1 Answer

Need to press 3 times to pause in-game in Unity 0 Answers

Game doesnt start playing automatically after pressing restart. 0 Answers

Pause menu script help 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges