- Home /
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()
{
}
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.
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.)
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.
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.
Yeah I was. I didnt get any errors, so I thought I could. I posted the cleaned up script.
Your answer
Follow this Question
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