Mesh Selection in Dropdown??
I would like to be able to Load a Mesh from an Option in my Dropdown UI, I set the rows to about 7, Renamed them all. Ive been researching the "On Value Changed" VS On Click Event and realized they are quite different. Can I make a Selection of a dropdown option the Same as an "On Click"? and how...really I want two dropdown menus.. One to select a Mesh...Second to select a texture for that Mesh...Any help or direction would be greatly appreciated!
Answer by TBruce · May 07, 2016 at 12:16 AM
Here is a start. It allows you to create all the drop down items from script. In the inspector I clear out all the drop down items as well as the label. Now for the image you need to create a UI image as a child of the Item game object in the DropDown template. Then drag that image reference to Item Image Field on the DropDown component.
The sample code below should do the rest (note you do need to set up the properties in the class below in the inspector).
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class DropDownManager : MonoBehaviour
{
public Dropdown dropDown1;
public Dropdown dropDown2;
public Dropdown dropDown3;
public List<string> strings = new List<string>();
public List<Sprite> sprites = new List<Sprite>();
public List<Dropdown.OptionData> optionData = new List<Dropdown.OptionData>();
// Use this for initialization
void Start ()
{
if (dropDown1 != null)
{
dropDown1.options.Clear();
for (int i = 0; i < strings.Count; i++)
{
dropDown1.options.Add(new Dropdown.OptionData(strings[i]));
}
dropDown1.value = 0;
}
if (dropDown2 != null)
{
dropDown2.options.Clear();
for (int i = 0; i < strings.Count; i++)
{
dropDown2.options.Add(new Dropdown.OptionData(sprites[i]));
}
dropDown2.value = 0;
}
if (dropDown3 != null)
{
dropDown3.options.Clear();
for (int i = 0; i < optionData.Count; i++)
{
dropDown3.options.Add(new Dropdown.OptionData(optionData[i].text, optionData[i].image));
}
dropDown3.value = 0;
}
}
}
Above three DropDown examples are provided
Drop down list 1 is a text only drop down
Drop down list 2 is a sprite only drop down
Drop down list 3 is a can be text only, sprite only or a combination
Answer by Adamhudson90 · May 08, 2016 at 06:04 PM
Thank you so much for all of your help. I am definitely going to mess with all of this later^^ My other question is, is it possible in unity to select a mesh from the dropdown, instantiate it to the screen, then click a second dropdown of textures, and have that selected texture apply to the mesh. I need to be able to call models from the dropdown, while destroying the old model..then have a list of textures that can be used on any of the called models universally.
Your answer
Follow this Question
Related Questions
Several instances destroyed when one is shot by player 0 Answers
Instantiate an object and destroy it after given time 2 Answers
Unable to delete instance of GameObject 0 Answers
Destroy Instantiate is not working 0 Answers
Destroy the first instantiated clone after 4 have been instantiated 1 Answer