- Home /
Little help with GUI Toggle needed
Hey.
I'm just wondering if someone could help me out a little bit with a GUI.toggle function. I'm working from the example documented here: http://unity3d.com/support/documentation/Components/gui-Controls.html, which uses the following example:
toggleBool = GUI.Toggle (Rect (25, 25, 100, 30), toggleBool, "Toggle");
The code that I'm having a problem with is:
Initial.autosubmit = GUI.Toggle(Rect(325,150,100,50),Initial.autosubmit,"");
I'm getting this error message: Assets/menugui.js(14,32): BCE0023: No appropriate version of 'UnityEngine.GUI.Toggle' for the argument list '(UnityEngine.Rect, int, String)' was found.
I'm confused here, because as far as I can tell mine has the exact same syntax as theirs.
Initial.autosubmit is defined in Initial.js, as:
static var autosubmit=0;
Answer by qJake · May 16, 2010 at 07:07 PM
I see two problems, one of which is one of the reasons I don't use Javascript at all.
static var autosubmit = 0;
Javascript interperets that as an integer, and the GUI.Toggle
function takes a boolean, not an integer. You want:
static var autosubmit : bool = false;
The other potential problem I see (though this probably isn't an issue), is that you left out your GUIStyle parameter on the end. Either insert a style name, or leave the parameter out.
Initial.autosubmit = GUI.Toggle(Rect(325, 150, 100, 50), Initial.autosubmit);
Thankyou very much. I chose to use Javascript for this, because as a complete beginner, Javascript was the language I'm familiar with. I have web experience, and it was one of the reasons I chose unity. :)
For your first solution, that was exactly it, thanks! I see why the error had int now, cheers. If anyone is reading this for the solution though, use boolean rather than bool. :)
The second issue wasn't a problem. It's not a style parameter, it's a string. In the example code, it's "Toggle", but I don't need any text next to it. I just left it in case it was needed.
Thankyou very much!
Your answer
Follow this Question
Related Questions
Is there a multiple selection ugui toggle group? 1 Answer
GUI toggle on click, unless on GUI. 1 Answer
Whats wrong with my GUI.Toggle? 2 Answers
why doesnt my script turn off on toggle? 1 Answer
Switching between set of components 1 Answer