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 superpentil · Aug 07, 2012 at 10:38 AM · guiinputtimebooleanpause

Creation of a Pause and a Console Menu?

I want to create a Pause menu and a Console Menu. I had a script that is really jumbled up, so im not going to post it. But in it I had it get when the Escape key was pressed. The problem is, I have to hold it, for the GUI window to stay. (I have the Time.timeScale thing in mind for things to be paused.) And when I did have the window on screen, No matter what I do, It seems that the window size or position cant be changed.

The other thing I had a problem with was, when using the TimeScale set to 0, I had to hold the escape button for it to be at 0, otherwise it goes back to 1. I just want to press it once and be done. I don't know the boolean thing to put to accommodate the if statement with, so help on this would be appreciated.

EDIT: Here's my code after scraping away at the dumb stuff I was trying to do.

 var windowRect0 : Rect = Rect (20, 100, 120, 10);
 var windowRect1 : Rect = Rect (20, 100, 120, 50);
 
 function OnGUI() 
 {
  if(Input.GetKey(KeyCode.Escape))
  {
  windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "Pause");
  Debug.Log("hi");
  }
  
  if(Input.GetKeyDown(KeyCode.C))
  {
  windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "Console");
  }
  
 }
 
 function DoMyWindow (windowID : int)
 {
  if (GUI.Button (Rect (15, 15, 100, 30), "Main Menu"))
  {
  //load main level
  }
 } 
 
 function Update()
 {
  
 }
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

Answer by TheDavil86 · Aug 07, 2012 at 05:15 PM

Well the reason you have to hold Escape is because you're probably using Input.GetButton or Input.GetKey. Basically you need to use GetButtonDown or GetKeyDown and then add in a flag that tells you whether or not the menu is up. Then each time the button is pressed it should check to see if the menu is up. If it is up, then it gets rid of it, if it's not up then draw it. All that has to be in a while look and don't forget to put in a yield at the end of it.

Same thing with the timescale, it should all be in the OnGui function.

If you want to be able to adjust the size of menu in game, you need to do some code for that and I'd recommend getting a bit more familiar with things before you try. The Gui window's sizes are defined in the code and you'd have to change them in real time for that to work.

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 superpentil · Aug 07, 2012 at 11:29 PM 0
Share

I was trying, but they still weren't changing. The first two numbers when you define the window are how you change the size right? (I was trying the last two to see if those were it, but still noting was happening.)

avatar image TheDavil86 · Aug 12, 2012 at 12:22 AM 0
Share

No the first 2 numbers are the upper-left most pixels, the next 2 are the length in pixels. So for example: (0,0,50,50) would be a box at the top left of the screen that is 50 pixels high and 50 pixels wide. It actually goes down and right for the sizes.

To make something that scales with the screen use Screen.width or Screen.height. If you divide those both by 2 you get roughly the center pixel of the screen regardless of what resolution is being used.

avatar image
0

Answer by Sundar · Aug 07, 2012 at 05:13 PM

The most obvious thing that I can imagine that is happening in your code is that you may be declaring the Boolean inside OnGUI function. You have to declare it outside and assign default value at start. Without your code I can't really give a correct answer except making assumption like this, I hope you understand.

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 superpentil · Aug 07, 2012 at 11:17 PM 0
Share

Yeah I was. I didnt get any errors, so I thought I could. I posted the cleaned up script.

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

9 People are following this question.

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

Related Questions

GUI Button appears when Paused 1 Answer

Timer Pause 1 Answer

Time.timeScale = 0 breaks my GUI. 0 Answers

GUIText which corresponds with a GUIBox 1 Answer

how to make a highlight gui ?? 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