I want to have a drop down menu that can change the text in each field during runtime (using an enum). I have an enum set up, but I can’t figure out or find any way to change the text of the options from script.
You need to import:
using UnityEngine.UI;
and then use this code:
public Dropdown dropdown;
void Start () {
dropdown.options.Clear ();
dropdown.options.Add (new Dropdown.OptionData() {text = "your stuff"});
}
If you want to change only a single Item:
Dropdown thisDD;
void Start ()
{
thisDD = GetComponent<Dropdown>();
}
void changeDDItemText(string newText,int index)
{
if (index < thisDD.options.Count)
{
Dropdown.OptionData newItem = new Dropdown.OptionData(newText);
thisDD.options.RemoveAt(index);
thisDD.options.Insert(index, newItem);
}
}
If you wanna change the whole dropdown menue:
void newDD(List<string> newDDList)
{
thisDD.options.Clear();
foreach (string option in newDDList)
{
thisDD.options.Add(new Dropdown.OptionData(option));
}
}