x


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()
{

}
more ▼

asked Aug 07 '12 at 10:38 AM

superpentil gravatar image

superpentil
13 1 8 10

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Aug 07 '12 at 05:15 PM

TheDavil86 gravatar image

TheDavil86
38 3 5 6

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.)

Aug 07 '12 at 11:29 PM superpentil

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.

Aug 12 '12 at 12:22 AM TheDavil86
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Aug 07 '12 at 05:13 PM

Sundar gravatar image

Sundar
581 2 2

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

Aug 07 '12 at 11:17 PM superpentil
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3695
x956
x573
x262
x240

asked: Aug 07 '12 at 10:38 AM

Seen: 351 times

Last Updated: Aug 12 '12 at 12:22 AM