|
I have a couple of buttons that pop up when you press a specific hot key and then when you press the GUI button, it does a specific action. For example, when I press escape, it brings up a "Quit" button which brings you back to the main screen when you click it. The problem I'm having is when I press Esc again, i'd like the GUI button to disappear, you know, toggle it on and off. Here's the JS code i have for it now, I don't know what to change to actually get it to work, I've tried putting things like quitMenu = !(quitMenu); and other variations of the code, but nothings working. It either disables the button entirely, or just ignores the code.
If anyone can help, I'd be greatly appreciative.
(comments are locked)
|
|
Well, good news, this solution is tested :) I was curious why it didn't work, the logic seemed right. Turns out, for whatever reason, having an Input() in the OnGUI() call is a bad idea. I was getting double-clicks of my escape key. By moving Input() down to Update(), it worked fine. Also note I used GetKeyUp(KeyCode.Escape) The actual complete (C#) code. Note that this should be in a file called *s_GUI.cs*, to match the Class name: This one isn't working for me either. Just getting a long list of errors in the code, and none of it seems to be happy when I try to adjust it.
Mar 12 '10 at 12:31 AM
CalledToGaming
Really? Strange, I just cut/paste the code above back into my script, and it worked fine. The code above is correct. :) Granted, I left out the quitMenu variable declaration, but that should be obvious. And I also presume you noticed it was C# code, not Javascript? So what kinds of errors are you getting? Try a new project with the minimal code to put up a button.
Mar 12 '10 at 01:57 AM
Cyclops
As for the differences - to make it Javascript, the only things I see are - changing the void to function, and removing the new keyword.
Mar 12 '10 at 02:07 AM
Cyclops
No, i know it's supposed to be in C#, it's giving me the error...CSTEST.cs(1,6):error CS0116: A namespace can only contain types and namespace declarations. so after the first "void" statement. Don't really know what it's problem is.
Mar 12 '10 at 08:16 PM
CalledToGaming
Okay, that's a different problem. :) I updated the code to contain a complete working file. Start with an empty C# script file, named s_GUI.cs, cut/paste this in. You can name it something else, but the filename must match the classname in the C# declaration, or you get errors.
Mar 13 '10 at 02:35 AM
Cyclops
(comments are locked)
|
|
Here is a more complete example written in
Now in more details. From the inspector you are able to change the Good luck and have fun! hey Lipis Thanks a lot, i used your code and it works perfectly, just two small typos ... in the Awake you have two times var x ... and "GUILayout.BeginArea(Menu.rect)" is not compiling because it doesn't know what Menu is. If i leave only the rect then it is working perfectly.
Aug 11 '10 at 11:59 AM
alexnode
(comments are locked)
|
|
This is off the top of my head, not tested... private var quitMenu; function OnGUI () {
} Nope, didn't do the trick :\
Mar 11 '10 at 11:37 PM
CalledToGaming
Try this code but do what Cyclops did below and put the input section into the function Update() instead of in OnGUI. That should work.
Mar 12 '10 at 02:02 AM
Ony
(comments are locked)
|
