How to add items to dropdown based on what's in a folder?
I'm wanting to create a script to add in entries to a dropdown list based on if there is an image (png) in a folder.
code: using System.IO; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ChangePart : MonoBehaviour {
public Dropdown ddlist;
void Start () {
ddlist.options.Clear();
foreach(FileInfo f in new DirectoryInfo("Assets/things").GetFiles("*.*")){
string[] s = f.Name.Split(".".ToCharArray());
//if(s[s.Length - 1]=="png") ddlist.options.Add(new ddlist.OptionData(s[0]));
}
}
}
I'm getting this error however: 'ChangePart.ddlist' is a 'field' but a 'type' was expected
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612124004im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to close a popup on a click of a button with an open dropdown menu? 0 Answers
Reuseable Dropdown 0 Answers
Animated Icon in Unity Dropdown Menu 0 Answers
Creating multiple text components on a canvas 1 Answer
Dropdown will not change selected item text after changing options list at runtime 5 Answers