Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DyrdaOrg · Nov 09, 2015 at 10:48 PM · c#inputpause menuswitchingpausing

Pause Menu script not working properly

So... I have this problem. It might be even a little funny, but I almost lost all hope for solving it so I'm kindly begging you for help.

This is my pauseScript.cs which is working... in a mysterious way.

First - If the game is on and player will die I'm triggering GameOver function from this script. Game pauses, pausePanel is showing up and I can restart game or go to the main menu. Working like a charm.

The problem is when I want pause game. First of all is remembering my clicks as it happened during the gameplay, so after resuming game my hero will jump like crazy squirrel (which he is not unfortunately cause that way I could have "feature" and not a bug). Second problem is happening after pausing game, resuming and then inevitable GameOver is coming... though it's not :( Player is destroyed, sound is being played, vibration is on... but the camera won't stop, score is still counting and pause menu with gameover text and restart button is not showing up (you need to actually click on it, but even then no restart button is on - only resume one).

Please help me since I'm tweaking this code and it's probably something obvious but it still sneaking out my grasp.

 using UnityEngine;
 using System.Collections;
 
 public class pauseScript : MonoBehaviour {
 
     public static pauseScript instance;
 
     public bool paused;
 
     public GameObject gameOverText;
     public GameObject playButton;
     public GameObject replayButton;
 
     [SerializeField]
     private GameObject pausePanel;
 
 
     void Start () {
         paused = false;
         replayButton.gameObject.SetActive(false);
     }
     
 
     public void Pause(){
         paused = !paused;
         if(paused){
             Time.timeScale = 0;
             pausePanel.SetActive(true);
             playButton.gameObject.SetActive(true);
             replayButton.gameObject.SetActive(false);
             gameOverText.gameObject.SetActive(false);
         }
     }
 
     public void GameOver(){
         paused = !paused;
 
         if(paused){
             Time.timeScale = 0;
             pausePanel.SetActive(true);
             playButton.gameObject.SetActive(false);
             replayButton.gameObject.SetActive(true);
             gameOverText.gameObject.SetActive(true);
         }
     }
 
     public void ResumeGame(){
         paused = paused;
         if (paused){
             pausePanel.SetActive(false);
             Time.timeScale = 1;
                 
         }
     }
 
     public void GoToMenu(){
 
         Time.timeScale = 1;
         pausePanel.SetActive(false);    
         Application.LoadLevel("02-MainMenu");
     }
 
     public void Restart(){
         Time.timeScale = 1;
         Application.LoadLevel("05-Game");
     }
 
 }
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 DyrdaOrg · Nov 10, 2015 at 05:49 AM 0
Share

Anybody? I must say that after adding, deleting, again adding and again deleting lines in my code - I can't say that I see anything wrong - just simple booleans trying to work perfectly as designed and still... not working.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by GiyomuGames · Nov 10, 2015 at 07:13 AM

Without trying to really understand your logic, I can point out that you put:

 public void ResumeGame(){
          paused = paused;

I assume you meant paused = !paused;

Comment
Add comment · Show 2 · 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 ijidau · Nov 10, 2015 at 07:23 AM 0
Share

I would have also thought that it's best to set pause explicitly rather than invert the value, for the sake of safety and clarity.

avatar image DyrdaOrg · Nov 10, 2015 at 10:20 AM 0
Share

Ok - that wasn't what I needed but you, kind sir, steered me in the right direction. I managed changed all the paused=paused !paused to just false and true statements and after few tweaks it's working as designed. Thank you for your time and effort!

Now I have to only solve the problem when my inputs (touches) in pause menu are somehow stored and making my player jump after resu$$anonymous$$g game.

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

36 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

Related Questions

Telling the difference between a key press, double press and hold. 0 Answers

OnMouseButtonDown 1 Answer

In-Game Browser, help needed! 1 Answer

Input.GetKeyDown(...) loop glitches 2 Answers

Pause Menu Problems 1 Answer


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