Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 agentc0re · Dec 06, 2014 at 07:07 PM · uiguicanvaspanel

[4.6 GUI] Displaying my pause menu when ESC is pressed

EDITED QUESTION I have a script, in which i've layed out what i think would be the logical order of things that would need to happen when creating a pause menu. My question is, once the user presses ESC, how do I display the GUI Panel that i've already created using the new UI system. This Panel exists in a canvas which I made in another scene.

Thank you for any help! Even pointing me towards the right set of documentation. -Jon

 using UnityEngine;
 using System.Collections;
 
 public class InGameGUI : MonoBehaviour {
 
     private string GUImode = "gaming";
 
     // Use this for initialization
     void Start () 
     {
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(Input.GetKeyDown("escape")) //Pause game when escape is pressed
         {
             Time.timeScale = 0;
             GUImode = "paused";
         }
     }
 
     public void DisplayMenu()
     {
         if(GUImode == "paused")
         {
             //display pause menu here
 
             if(Input.GetKeyDown("escape")) //if escape is pressed to resume game
             {                
                 Time.timeScale = 1;
                 GUImode = "gaming";
             }
             if(/*add condition for when game is quit*/) //If quit button is pressed return to main menu
             {
                 Time.timeScale = 1;
                 GUImode = "quitting";
                 Application.LoadLevel("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
Best Answer

Answer by Kiwasi · Dec 06, 2014 at 08:55 PM

The UI system and OnGUI are completely separate systems, and should not be used together.

Move all of your OnGUI code to Update. Create a GameObject variable to store the panel. Use SetActive() to turn it on and off.

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 agentc0re · Dec 06, 2014 at 08:59 PM 0
Share

For the GameObject variable, can you give an example of how i would do that if the panel existed in another scene? Or is it a bad idea that my menu exists in another scene?

avatar image Kiwasi · Dec 06, 2014 at 10:34 PM 0
Share

$$anonymous$$ake the panel a prefab by dragging out of the scene an into the assets folder. Then you can recreate it in your new scene. You can't access a GameObject in another scene without changing scenes.

avatar image agentc0re · Dec 06, 2014 at 10:36 PM 0
Share

AHHh yes! This is great. Thank you so much for your help!

avatar image Kiwasi · Dec 06, 2014 at 11:13 PM 0
Share

DontDestroyOnLoad is also worth considering.

avatar image
-1

Answer by Ouss · Dec 06, 2014 at 08:46 PM

You call GUI methods, like GUI.DrawTexture, GUI.BOX, etc... Here is a link to a thread having almost same matter: http://answers.unity3d.com/questions/623781/making-a-gui-panel-appear-on-boolean-true.html

Comment
Add comment · Show 1 · 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 agentc0re · Dec 06, 2014 at 08:50 PM 0
Share

I thought GUI methods were the old GUI way before 4.6 new GUI (maybe it's only referred to as UI??). Thank you for the link, i will be sure to check it out.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Panels and CanvasGroup in UI management 0 Answers

UI Panels are not positioning themselves according to screen size 0 Answers

Button onClick events will not be triggered 1 Answer

Using Canvas/Gui with splitscreen(several cameras) 0 Answers

[VR] How to display a canvas with Oculus 5 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