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!



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)

So basically you can check the script for the declaration of the var “Controller”, and that will give you the name of the enum

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 :slight_smile: