- Home /
Combo Box script from C# to JavaScript
Hey, I am trying to create a drop down menu and found a script that does exactly what I need. The only problem is that it is in C# and I need help changing it to JavaScript. I was able to change most of the script except for this portion:
if (editing)
{
var x : int;
for (x = 0; x <= counter; x++)
{
if (GUI.Button(new Rect(Box.x, (Box.height * x) + Box.y + Box.height, Box.width, Box.height), items[x],userStyle))
{
selectedItem = items[x];
editing = false;
}
}
}
Here is the link to see the full script: http://www.mediafire.com/view/2w7dqlk226d4lm9/helloWorld.cs
Thanks!
or you can place the script into standard assets so that you can access the c# script, and not have to modify it you just can't have it do callbacks, or if that doesn't make sense you can use the one from the wiki (at the bottom)
The rest of my scripts are in java script, as I am new to Unity. Also, I need to reference variables from C# to JS and back. I tried the ones from the wiki earlier and couldn't get them working.
Oops, sorry. I just noticed you're going from C# to uJS. $$anonymous$$y mistake.
Here are the links from my deleted answer :
Links useful in converting between C# and JS :
I cannot see a problem. What is the problem? Is there an error message?
Is items an array of strings? If not, try :
if (GUI.Button(new Rect(Box.x, (Box.height * x) + Box.y + Box.height, Box.width, Box.height), items[x].ToString(),userStyle))
ps. I use the new keyword, there is no problem using new f or this =]
I think it is an array of strings. I do not know how to write that variable in js. Here are the errors: 1. changing items variable, (cannot convert 'null[]' to 'string') 2. with the if(GUI.Button....)(I'm assu$$anonymous$$g because of the items[x] variable) 3. with the selectedItem = items[x](Also because of the items[x] variable)
Thank you for helping!
Your answer

Follow this Question
Related Questions
Can I use hexidecimal colors in my GUI? 1 Answer
Lower player's health from separate script. 2 Answers
Astarpathfinding Scan all graphs 1 Answer
Sending the C# function parameter to JS function. 1 Answer
Information about Unity 0 Answers