- Home /
Two dynamic dropdowns from one source list
I'm using unity 3D to build a virtual map of my university. It should have a functionality of finding route from one Building to another (game objects are 3D models exported to Unity). Actual Path finding code is working fine. I have a UI panel where user can select the "Origin"(starting point of the route) and "Destination"(End point) from two dropdowns. I have added all those Buildings as game objects to a list ("originList") .For ease their names as string to"Buildings" list. These two dropdowns need to be dynamic. For an example if the user selects "Library" as the "origin" dropdown selection , "Library" should not appear as an option in the "Destination" . And the selection of each dropdown should be retrieved for the back end work. This is how I implemented my code but it doesnt seem to be working. Please bear with me since I am new to Unity 3D and the community . Help will be much appreciated. Thanks in advance. @Legend_Bacon I hope this has enough elaboration . Thanks for pointing out the vagueness in my previous question.
public Dropdown origin;
public Dropdown Destination;
public List originList = new List();
public List Buildings = new List();
private void Start(){
PopulateList();
}
public void PopulateList()
{ foreach (GameObject building in GameObject.FindGameObjectsWithTag("Player")){
originList.Add(building);
Buildings.Add(building.name);
Debug.Log(this + " is an active object");
}
origin.AddOptions(Buildings);
}
public int OriginGetValue(){
return origin.value;
} public void ModifyList(){
int var = OriginGetValue();
Debug.Log(originList[var].name);
Buildings.Remove(originList[var].name);
Destination.AddOptions(Buildings);
}
private void Update(){
ModifyList();
}
Hello there,
Indeed, this question is much clearer. Thank you for actually taking the time to reformulate like this.
You may want to edit your original post and format the code properly (throwing in a couple of spaces before and after should do the trick) so people understand it better.
I hope you'll find an answer soon.
Cheers,
~LegendBacon