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 karmik · Dec 05, 2016 at 04:07 PM · pausebutton trigger eventsresume

how to Pause game if score exceeds a number and display text and button to resume.

Hi Gurus I want to create a intractable button and then add on click action to it. Its not working now. Is there any example for this pls. My objective is to pause the game once user reaches a score. Enable a button along with some text. Once player clicks this button i want to resume by adding LevelResume function under onclick. The problem currently is the button is not clickable. Currently i am attaching the Resume button to Level_manager script on levelmanager object.

Can you please help.

public class Level_manager : MonoBehaviour { public GameObject resume;

     void Update()
     {
         if (ScoreManager.SavedScore == 10) 
         {

             resume.SetActive(true);
             Time.timeScale = 0;
         }
     }

     public void LevelResume()
     {
         Time.timeScale = 1;
         resume.SetActive(false);

     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tkamruzzaman · Dec 05, 2016 at 05:17 PM

Your Update() checks score == 10 and sets timeScale to 0 even if you set it back to 1 it sets it to 0. You can simply prevent this by adding a bool to the if() statement.

 public class Level_manager : MonoBehaviour 
 { 
      public GameObject resume;
      private bool isResumeShown;

      void Update()
      {
          if (ScoreManager.SavedScore == 10 && !isResumeShown) 
          {
              isResumeShown= true;
              resume.SetActive(true);
              Time.timeScale = 0;
          }
      }

      public void LevelResume()
      {
          Time.timeScale = 1;
          resume.SetActive(false);
      }
  }
Comment
Add comment · Show 3 · 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 $$anonymous$$ · Dec 05, 2016 at 05:47 PM 0
Share

I have a similar script that is not working... When the game is paused buttons don't work. I think that this happens because of timescale that is 0. Anyways you are right that you must check if the game is paused or not.

avatar image tkamruzzaman $$anonymous$$ · Dec 06, 2016 at 04:22 PM 0
Share

When Time.timeScale is zero button's OnClick event does work. You just have to assign timeScale to one upon button (resume button) click.

avatar image karmik · Dec 07, 2016 at 04:10 AM 1
Share

Thanks although i endedup deactivating and activating required game objects ins$$anonymous$$d of pausing the game, your approach did help me, i used the additional bool to check for activate/deactivate objects.

Trying to finish the game too quickly , stumbling on logical problems :)

avatar image
0

Answer by karmik · Dec 07, 2016 at 04:12 AM

My problem is same as eRlind, i went ahead with deactivating and activating required objects instead of pausing. Its looks much cleaner as the enemies will stop in their dying anim when the game is paused. Deactivating the game objects made more sense to me

Comment
Add comment · 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

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

57 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

Related Questions

How to stop Background music from resetting when i resume game 0 Answers

When Resuming game after losing focus I just get a black screen? 0 Answers

Best way to Pause/Resume an object rotation script? 0 Answers

Pause scene when character hit object, then resume it from another scene 0 Answers

THE OCULUS GO RESUME AND PAUSE PROBLEM WITH UNITY 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