Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding individual image in Dropdown item

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.

like image 922
AN90 Avatar asked Dec 13 '25 09:12

AN90


1 Answers

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.

like image 93
AN90 Avatar answered Dec 14 '25 21:12

AN90