Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by s_ruffin · Jul 19, 2013 at 05:52 PM · c# to javascript

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!

Comment
Add comment · Show 9
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gardian06 · Jul 19, 2013 at 05:57 PM 0
Share

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)

avatar image s_ruffin · Jul 19, 2013 at 06:00 PM 0
Share

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.

avatar image AlucardJay · Jul 19, 2013 at 06:14 PM 0
Share

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 :

  • http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

  • http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

  • http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

avatar image AlucardJay · Jul 19, 2013 at 06:17 PM 0
Share

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 =]

avatar image s_ruffin · Jul 19, 2013 at 06:37 PM 0
Share

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!

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges