I'm trying to load a separate image into Dropdown options. Changing image field of option in inspector doesn't give the desired result. I can't solve the problem in code:
public class FillDroPDown : MonoBehavior {
public Dropdown dd;
void Start () {
dd.options.Clear();
dd.AddOptions(new List<Dropdown.OptionData> {
new Dropdown.OptionData {text="1",
image=Resources.Load("LeftToRight.png", typeof(Sprite))
as Sprite}
});
}
void Update () {
}
}
The text is displayed, but there is no image. I have created a Resources folder and copied the image there. How this problem can be solved? My Unity version is 5.3.4f1.
The problem was solved in the following way: in path to the resource object is not necessary to add the file extension. Also in the Dropdown object you need to install Item Image property to "Item Background" of this Dropdown. To set image into the caption you can add Image object to Dropdown and set Caption Image property to this added image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With