- Home /
How can I attach a GUI.Button to a variable?
How would I do the equivalent of:
public var myVar: GUI.Button;
in Javascript? I need to make some GUI button elements editable in the Inspector.
Answer by NewfieJoe · May 29, 2011 at 01:27 PM
Actually I needed to make an array of buttons that were editable and easy to reference. I ended up doing this:
public var myButtons: myGUI[];
private class myGUI {
public var Label: String;
public var position: Rect;
public var content : GUIContent;
public var style : GUIStyle;
public function Button () {
if( GUI.Button(position,content,style)) return true;
else return false;
}
}
Answer by G_Sacristan · May 29, 2011 at 12:57 PM
If u want to change its style then use this:
//edit it in your inspector
var myStyle: GUIStyle;
function OnGUI()
{
GUI.Button(Rect(0,0,25,25),"MyButton",myStyle);
}
It should work! Cheers!
u dont have to use public in JavaScript, because all variables by default in JavaScripts are public, ins$$anonymous$$d of CSharp, where all variables by default are private;
So keyword public has no effect to variable in JS;
IF u want to make it global use static variable. Cheers!
I use public anyway simply because it's easy to read the code for others with coding experience in other languages if they are reading the post and in lists of variable declarations with mixed public and private vars it appeals to my OCD side. ;)
Your answer
Follow this Question
Related Questions
Make button clickable 2 Answers
Hide/show GUI Buion 1 Answer
Touch Control Android Java 0 Answers
Can't get 4.6 GUI Button to Load Scene (Solved) 1 Answer
GUI Button Disappearing 1 Answer