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 mdinizzz · May 14, 2012 at 11:31 PM · guidestroy

destroy gui after game paused

Destroy GUI after Paused Game Posted: 03:21 PM 1 Hour Ago Hello,

here is the escript to pause with the GUI:

 var pauseUI: Transform;
 
 function Update ()
 {
     if (Input.GetKey (KeyCode.Menu)) {
         pause ();
     }
 }
 
 function pause () {
     Time.timeScale = 0;
     Instantiate (pauseUI);
 }

How Do I Destroy the GUI after I put the Time.timeScale = 1; ? thanks for the help

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Justin Warner · May 14, 2012 at 11:51 PM

Psuedo code: isPaused = false;

 function awake()
 {
 isPaused = false;
 }
 function update()
 {
 //If pause is hit, make isPaused=true;
 //If pause is hit again, or unpause, w/e, make isPaused = false;
 }
 function update()
 {
 //If (isPaused)
 //Draw pause menu.
 //else
 //Draw game graphics.
 }

Rough and unformatted, but works.

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 Bunny83 · May 15, 2012 at 12:30 AM 2
Share

I guess your second update should be OnGUI? ;)

Even when it's pseudo code, why is Awake and Update lowercase?

avatar image
0

Answer by Bunny83 · May 15, 2012 at 12:24 AM

 var pauseUI : Transform;
 private var pauseInstance : Transform;
 
 function pause () {
     Time.timeScale = 0.0;
     pauseInstance = Instantiate (pauseUI) as Transform;
 }
 
 function unPause () {
     Time.timeScale = 1.0;
     if (pauseInstance != null)
         Destroy(pauseInstance.gameObject);
 }

About Instantiate & prefabs
Object.Instantiate()

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 mdinizzz · May 15, 2012 at 03:59 AM 0
Share

did not work :(

avatar image AlucardJay · May 15, 2012 at 05:08 AM 0
Share

did you drag and drop your GUI gameObject into the Inspector for this script's gameObject?

do you need to destroy the GUI, or just hide it?

 private var isPaused : boolean = false;
 
 function Update() 
 {
     if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.P))
     {
         if (isPaused)
         {
             isPaused = false;    
             Time.timeScale = 1.0;
         } 
         else 
         {
             isPaused = true;
             Time.timeScale = 0.0;            
         }
     }
 }
 
 function OnGUI()
 {
     if (isPaused)
     {
         GUI.Box(Rect(10, 10, 200, 25), "is PAUSED");
         Debug.Log("Hello World");
     }
 }
avatar image
0

Answer by mdinizzz · May 15, 2012 at 04:06 AM

I found the solution simply Search for the UI then destroy it. It would be best if you give the tag That UI ("UI")

Destroy (GameObject.FindWithTag ("UI")),

:)

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 Bunny83 · May 15, 2012 at 10:08 AM 0
Share

That's the most inefficient way. If something else is tagged "UI" (maybe by accident) it won't do what you expect.

Can you tell me what exactly "did not work" mean? Any errors? What happens?

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

GUI Appear Help 1 Answer

Setting Scroll View Width GUILayout 1 Answer

how to destroy an object permanently ? 1 Answer

C# How to Drag and Scale with Mouse Window 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