Tutorial for Dropdown item needed
I'm planning to use the drop down menu item in the UI for a character generator script. I can't find any tutorials on it. There are plenty of "do it yourself" drop down, but there is an actual drop down, but I'm not sure how to work with it. Does anyone know of any tutorials working with this?
Thanks!
Answer by Riderfan · Feb 16, 2016 at 04:08 AM
He's not asking about building a drop down menu, he's asking about the drop list that's a standard UI component.
Sadly, the drop menu UI component is lacking in good tutorials. I managed to get mine working although it's certainly not working like any drop list I've ever used.
Basically to add items you call the following;
string stringtoadd = "Some String Value";
_DropToFill.options.Add(new Dropdown.OptionData() { text = stringtoadd });
That will add the 'stringtoadd' variable to the drop list as a selectable item. Do this for each item you need to add (so itterate through an array or whatever).
To determine what value of the list has been selected create an appropriately named method and apply that to the OnValueChanged event of the dropdown list component in the Inspector. Note, the OnValueChanged event is called anytime a user simply clicks on the drop list as opposed to when the value is actually changed(!) This strikes me as a Unity bug becuase the name implies that the event should only happen when the value of the drop list changes (otherwise it would be an OnClick event).
Anyway, hopefully that gets you started.
Thanks Riderfan! $$anonymous$$aybe it's been corrected with the latest version, but I'll have to wait to get a new OS before I can update.
Your answer
Follow this Question
Related Questions
Change graphics with Dropdown 0 Answers
Unity Dropdown Menu Not Closing 1 Answer
What is a good way to create dynamic dropdown buttons? 0 Answers
Writing dropdown selections to file 1 Answer
How delete options from the dropdown gui withscript? 0 Answers