Some quick help with retrieving the value of selected object?

0 votes
asked May 19, 2016 in Help by anonymous
I'm newer to Unity and would appreciate some help.  Could you post a quick example on how I could implement the ability to get the selected value of something like a dropdown?

1 Answer

+1 vote
answered May 19, 2016 by anonymous
selected May 26, 2016 by admin
 
Best answer

I figured it out! This is what I did, pretty simple. My roadblock was just figuring out how to attach my script/component and connect it to the OnItemSelected.

using UnityEngine;
using MaterialUI;

public class MaterialCustom : MonoBehaviour {
  public void OnDropdownSelect() {
    MaterialDropdown dropdown = GetComponent<MaterialDropdown> ();

    int currentlySelected = dropdown.currentlySelected;
    string currentlySelectedName = dropdown.optionDataList.options [currentlySelected].text;

    Debug.Log (currentlySelectedName);
  }
}

 

Welcome to MaterialUI support! Ask us anything :)
...