How do I get the index value of a Dropdown Selection?
Hey guys! Total newbie here.
I want to call the index value of a dropdown selection, but I have no idea how to do that. Any thoughts?
Answer by Ameisenfutter · Nov 14, 2016 at 06:46 PM
Solved it! Here's my code, for anyone looking for an easy solution. Add a script with this code to the Dropdown GameObject and assign it and the specific function ("onHerkunftChoose" in my case) to the dropdown OnValueChanged!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HerkunftDropDown : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void onHerkunftChoose () {
int chosenInt = GameObject.Find ("HerkunftDropdownMenu").GetComponent<Dropdown>().value;
print (chosenInt);
}
}
Answer by AKFesnf · Dec 13, 2017 at 02:27 AM
Just a question, what was your problem that you had? I want to see if i can use it to solve my own problem.
He needed the index element selected on a dropdown, his solution: int indexElement= GameObject.Find ("HerkunftDropdown$$anonymous$$enu").GetComponent().value;
Your answer
Follow this Question
Related Questions
TMP Dropdown resets its value 0 Answers
UI Dropdown problem. 1 Answer
Missing XboxLiveUser script 0 Answers
Issue Running a startup script 2 Answers
Collider with more health wins collision? Please Help! 0 Answers