Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 /
avatar image
0
Question by CoreApp2 · Sep 08, 2015 at 01:12 PM · androidguimenu screenescape

press esc to show a GUI menu

Hello

I wrote currently a game code, but im stuck with a big problem. I want that, when the esc key is pressed, the menu is showed.

That is my hierarchy:

Canvas

Panel

TextScore // to show the score on the screen

FinishMenu // when the level is complete

QuitButton

MenuButton

NextButton

EscapeMenu // whenn you press esc key, menu is showed

QuitButton

MenuButton

ReplayButton

ContinueButton

FallDownMenu // when the player die, the menu is showed

QuitButton

MenuButton

ReplayButton

PauseButtonImage // Image ( || ) for pause on the screen

a) when the level is complete, a menu is showed with differents buttons like in the hierarchy. it works

b) when the player (gameObject) dies, a menu is showed. It works like a)

c) But while you play and try the esc key, the game is paused but the menu is not showed that is the code

 public GameObject escapeMenues;
     public bool isPaus;
     private int escCount = 0;
 
     public Text textScoreText;
     public Text topScoreTop;
 
     void Start()
     {
         isPaus = false;
         escapeMenues.SetActive(false);
     }
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.Escape) && escCount == 0)
         {        
             setPause();
            
             SetCountText();
             escapeMenues.SetActive(true);           
             escCount = 1;
         }
         if (Input.GetKeyDown(KeyCode.Escape) && escCount == 1)
         {          
             setPause();          
             escapeMenues.SetActive(false);           
             escCount = 0;
         }
     }
 
     public void loadNaechsteLevel()
     {
         //Application.LoadLevel(_levelName);
         Application.LoadLevel(Application.loadedLevel + 1);
     }
 
     public void loadSelbeLevel()
     {
         Application.LoadLevel(Application.loadedLevel);
     }
     public void loadMenu()
     {
         Application.LoadLevel("Menus");
     }
     public void VerlasseDasSpiel()
     {
         Application.Quit();
     }
 
     public void setPause()
     {
         if (!isPaus)
         {
             Time.timeScale = 0;
         }
         else
         {
             Time.timeScale = 1;
         }
         isPaus = !isPaus;
     }
 
     void SetCountText()
     {
         textScoreText.text = RotateSphere.countPickUp.ToString();
         topScoreTop.text = RotateSphere.topScore.ToString();
     }


I assigned public GameObject escapeMenues with EscapeMenu in my hierarchy

I also tried to debug it. I wrote some Debug.Log(); in to if (Input.GetKeyDown(KeyCode.Escape) && escCount == 0). It works of cause, then the game is paused but the menu is not showed.

The plattform is android

Please i need you help, thank you !!

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 DiegoSLTS · Sep 08, 2015 at 05:58 PM 0
Share

Can you share the code that does work? The one used when the player completes the game or dies.

Are you sure Canvas and Panel are active? escape$$anonymous$$enues.SetActive(true); should make that object visible again.

Also, you said it's an Android project, does it work in the editor but not in Android or fails in both?

2 Replies

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

Answer by MakakWasTaken · Sep 08, 2015 at 06:45 PM

You could try this instead:

 void Update()
      {
          if (Input.GetKeyDown(KeyCode.Escape))
          {        
              setPause();
             
              SetCountText();
          }
      }
 
 public void setPause()
      {
          if (!isPaus)
          {
              Time.timeScale = 0;
          }
          else
          {
              Time.timeScale = 1;
          }
          isPaus = !isPaus;
          escapeMenus.SetActive(isPause);
      }
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 CoreApp2 · Sep 08, 2015 at 07:08 PM 0
Share

You mean 22. escape$$anonymous$$enus.SetActive(false); it doesnt work !!

avatar image CoreApp2 · Sep 18, 2015 at 10:19 AM 0
Share

I think the application is good !! i've done something like

  void Update()
     {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
         {
             setPauseEscape();
         }
     }
 public void setPauseEscape()
     {
         if (!isPause)
         {
             Time.timeScale = 0;
             escape$$anonymous$$enues.SetActive(true);
         }
         else
         {
             Time.timeScale = 1;
             escape$$anonymous$$enues.SetActive(false);
         }
         isPause = !isPause;
     }

i didnt know why setActive dont work in update() Ths for help !!

avatar image
0

Answer by CoreApp2 · Sep 09, 2015 at 09:41 AM

This is how the scene window look

![t][1]

and the game window

!

and the code that work with the other menu

     public Text winText;
     public Text textScoreText;
     public Text topScoreTop;
 
     public GameObject imageScore;
 
     public bool isPaus;
 
     // Use this for initialization
     void Start () {
         winText.text = "";
         isPaus = false;
         imageScore.SetActive(false);      
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     IEnumerator OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("Player"))
         {
             winText.text = "Level Complete!";
             Destroy(other.gameObject);
             yield return new WaitForSeconds(2);
             Destroy(winText);
             SetCountText();
             imageScore.SetActive(true);          
         }
     }
 
     void SetCountText()
     {
         textScoreText.text = RotateSphere.countPickUp.ToString();
         topScoreTop.text = RotateSphere.topScore.ToString();
     }
 
     public void VerlasseDasSpiel()
     {
         Application.Quit();
     }
 
     public void setPause()
     {
         if (!isPaus)
         {
             Time.timeScale = 0;
         }
         else
         {
             Time.timeScale = 1;
         }
         isPaus = !isPaus;
     }
 
     public void loadNaechsteLevel()
     {
         Application.LoadLevel(Application.loadedLevel + 1);
     }
 
     public void loadSelbeLevel()
     {
         Application.LoadLevel(Application.loadedLevel);
     }
     public void loadMenu()
     {
         Application.LoadLevel("Menus");
     }


On the smartphone the pause and esc button doesnt work and when i touch on the screen, it seems to pause the game rather than jump. Maybe it is the gui. But i think what ive done with the gui is correct. I already spent a lot of time with it. Pls i need u help !

http://answers.unity3d.com/answers/1063762/view.html

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Main Menu - One scene or multiple? 1 Answer

Problem in game Orientation 0 Answers

How can I detect if the back button is virtual or physical? Hardware or Software Device buttons 2 Answers

Android Options Menu 0 Answers

Is there a way to scroll GUI text WITHOUT scrollbars? 2 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