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
1
Question by code-blep · Aug 05, 2012 at 03:16 PM · javascriptmodify

Change value of dropdown using JS

I am having problems changing a value of a dropdown in a component. I can do things like disable/enable the component for example:

 scriptName1.GetComponent("VisGameObjectPropertyModifier").enabled = false;

But I seem unable to change the value for a drop down list in that component. The Option is called 'Controller', and the values in the drop down are 'High', 'Medium', 'Low'.

I've tried all sorts of ways, but end up getting null references, unexpected tokens, and all sorts of other stuff.

Hope someone can give me a nudge in the right direction!

Thanks

Paul

Comment
Add comment · Show 3
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 RodrigoSeVeN · Aug 05, 2012 at 03:26 PM 1
Share

When you say "Option", do you mean 'Controller' is a variable? If it is a variable inside your component, you just need to call it and set the new value. You take the "enabled" from that sentence and replaces with the variable name, and after the "=", you just set the new value. If not the case, you might want to post your code, so we can see how your 'Controller' is coded into your component.

avatar image code-blep · Aug 05, 2012 at 03:37 PM 1
Share

Thanks for the reply Rodrigo! I can't post the script for the controller as it is an asset bought off the Unity Store (Visulaizer Studio).

I guess Controller is a variable as the options for 'High' etc are it's drop down.

avatar image code-blep · Aug 05, 2012 at 03:39 PM 0
Share

I did try what you suggested before I posted as it seemed the most logical. Here it is: scriptName1.GetComponent("VisGameObjectProperty$$anonymous$$odifier").Controller = High;

But I get the error: BCE0005: $$anonymous$$ identifier: 'High'.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Seth-Bergman · Aug 05, 2012 at 03:37 PM

by "dropdown" I assume you mean enum. So, to change the value, you would say (depending on the name of the enum and the instance of said enum):

 enum MyDropdown {high,medium,low}; // this is the enum
 var Controller : MyDropdown; // this is the instance we see in the inspector

to set it, you would say:

 Controller = MyDropdown.high;

to compare:

 if (Controller == MyDropdown.low)

etc.. So basically you can check the script for the declaration of the var "Controller", and that will give you the name of the enum

Comment
Add comment · Show 4 · Share
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 code-blep · Aug 05, 2012 at 03:51 PM 0
Share

Hi Seth! O$$anonymous$$, I need to go read up on enum (first I have ever heard of it!). It says 'Controller' in the inspector panel, so am I safe to assume that is it's real var value to target?

Thanks for the code examples. $$anonymous$$uch appreciated.

avatar image code-blep · Aug 05, 2012 at 03:53 PM 0
Share

I ask about the var, as it's a component I bought from the Unity Store, and not something I wrote myself.

avatar image Seth-Bergman · Aug 05, 2012 at 04:38 PM 1
Share

yes, it's safe to assume, although it's probably not capitalized now that I think about it.. to figure it out, add the line :

controller = "hello";

to the start function, or awake, or update..

this will throw an exception, which will tell you the name of the data type!

it will say:

cannot convert 'String' to 'NameOfEnum'

then, you know how to access it:

scriptName1.GetComponent("VisGameObjectProperty$$anonymous$$odifier").controller = NameOfEnum.High;

if lowercase doesn't work (unknown identifier 'controller') try uppercase

Controller = "hello";

avatar image code-blep · Aug 05, 2012 at 05:10 PM 0
Share

Seth, that is a brilliant idea. Thanks for your help!

avatar image
1

Answer by code-blep · Aug 09, 2012 at 07:35 PM

For anyone else using the Visualizer Studio I found the following worked great when trying to change a different property (in this case the 'Target Property' dropdown) but it works just the same:

 //Specify the game object in the inspector panel
 var scriptName1 : GameObject; 
 
 //The targetProperty = 12; is the value for 'Uniform Scale' just count down the list (starting with 0) to find the correct value   
 scriptName1.GetComponent("VisGameObjectPropertyModifier").targetProperty = 12;

Hope it helps, and again thanks to Seth for putting me on the right track :)

Paul

Comment
Add comment · Share
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

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

9 People are following this question.

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

Related Questions

unity javascript indirection 1 Answer

How to go about modifying a variable in a C# script from within a UnityScript (Javascript) that resides in a different Gameobject? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Modifying animation keyframes using javascript? 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