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 /
avatar image
1
Question by Skelowoort · Aug 06, 2016 at 07:51 PM · c#scripting problemdisablepause menu

C# problem with pause menu

First of all my english is bad so sorry my mistakes writting. I'm trying to make work a pause menu which use canvas and timescale works, but if I press the movement keycodes the object still moving so i decided if the timescale = 0 disable the scrip of the object but i had a lot of issues and i can't find a solution so anyone could help me? this is my pause script: public class pause : MonoBehaviour { public Transform canvas;

 // Use this for initialization
 void Start () {
     
 }
         
 // Update is called once per frame
 void Update () 
 {
     if(Input.GetKeyDown (KeyCode.Escape)) 
     {
         if (canvas.gameObject.activeInHierarchy == false) {
             canvas.gameObject.SetActive (true);
             Time.timeScale = 0;
             if (canvas.gameObject.SetActive (true)) 
             {
                 GetComponent<Group> ().enabled =(false);
             }

         } 
     }

 }
 public void Return()
 {
     canvas.gameObject.SetActive (false);
     Time.timeScale = 1;
     if (canvas.gameObject.SetActive (false)) 
     {
         GetComponent<Group> ().enabled =(true);
     }

 }
 public void Exit()
 {
     SceneManager.LoadScene ("MainMenu");
 }
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
1

Answer by Masterio · Aug 07, 2016 at 04:06 PM

You can set the time scale to 0.00001f or make your UI scripts independends from the time scale by using custom time (you can find it on this forum).

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 Skelowoort · Aug 07, 2016 at 10:55 PM 0
Share

$$anonymous$$y game is a tetris and the movement of the pieces doesn't work with a float. That's how it works: void Update () {

     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftArrow)) {
         // $$anonymous$$odify position
         transform.position += new Vector3(-1, 0, 0);

         // See if valid
         if (isValidGridPos())
             // Its valid. Update grid.
             updateGrid();
         else
             // Its not valid. revert.
             transform.position += new Vector3(1, 0, 0);
avatar image Masterio Skelowoort · Sep 07, 2016 at 07:18 PM 0
Share

You can apply this solution if you have some energy for rework updated metohds:

 Create static variable paused in class Game (you can place this static variable in any class, this class should be permament per level i mean do not remove this object when level is loaded)
 
 public class Game : $$anonymous$$onoBehaviour
 {
    public static bool paused = false;
 }
 

Next place in every update method what execute block spawn/move this lines:

 if(Game.paused)
    return;
 

Next if you pause the game set the Game.paused = true; if you unpause the game then Game.paused = false;

avatar image Masterio Skelowoort · Sep 07, 2016 at 07:43 PM 0
Share

this script can be optimized by the:

  if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftArrow)) 
     {
       if ( transform.position.x > leftBorderX)
       {
             // move if position is valid
              transform.position -= new Vector3(1, 0, 0);
     
               updateGrid();
       }
     else if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.RightArrow)) 
     {
 
       if ( transform.position.x < rightBorderX)
       {
             // move if position is valid
              transform.position += new Vector3(1, 0, 0);
     
               updateGrid();
       }
 
 }
 
 


avatar image
0

Answer by danivdwerf · Aug 08, 2016 at 07:27 AM

Try this maybe

Don't know if how you did it in your hiearchy, but you should put all your pause stuff in a panel


public class Pause : MonoBehaviour 
{
    [SerializeField] private GameObject pausePanel;
    
void Start() { pausePanel.SetActive(false); }
void Update() { if(Input.GetKeyDown (KeyCode.Escape)) { if (canvas.gameObject.activeInHierarchy == false) { PauseGame(); } if (canvas.gameObject.SetActive (true)) { ContinueGame(); } } }
private void PauseGame() { Time.timeScale = 0; pausePanel.SetActive(true); /DisableControllers }
private void ContinueGame() { Time.timeScale = 1; pausePanel.SetActive(false); /EnableControllers } }

Also, did you make an empty object called GameController where you put the pause script on? it's not required, but very helpfull

Good luck

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

7 People are following this question.

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

Related Questions

Audio plays only once and not playing on click of button again(using audio manager script) 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Script disabling itself 3 Answers

Why don't I get 20 poits in my trigger function? 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