How do you access the text value of the Dropdown UI?

Whenever the value is changed, I need to get the text as string and print it out. I have tried using the code below but it always returns null. Thank you in advance.

var LocationPicker : GameObject;
var LocPickerString : String;

function Start () {

LocPickerString = LocationPicker.GetComponent.<UI.Dropdown>().OptionData().text;

Debug.Log(LocPickerString);}

You can simply do this:

Debug.Log(Dropdown.options[Dropdown.value].text);

I couldn’t get the above answers to work, so here is another (simpler) option for future readers:

    //find your dropdown object
		public Transform dropdownMenu;

    //get the selected index
		int menuIndex = dropdownMenu.GetComponent<Dropdown> ().value;

    //get all options available within this dropdown menu
		List<Dropdown.OptionData> menuOptions = dropdownMenu.GetComponent<Dropdown> ().options;

    //get the string value of the selected index
		string value = menuOptions [menuIndex].text;

Turns out that the selected value is always reflected real time in the Text component of a child of the Dropdown, which is the Label. So here is what I had done:

var LocationPickerLabel : GameObject;
private var SelectedLocation : Text;
var LocName : String;

function Start () {

SelectedLocation = LocationPickerLabel.GetComponent(UI.Text);

LocName = SelectedLocation.text;}

A little out of topic, but I can also set the value from the start and therefore typing in an instruction before the drop down is pressed by typing SelectedLocation.text = “Any instruction that I need …” in the start function.

Try:
LocPickerString = LocationPicker.GetComponent.<UI.Dropdown>().itemText.text

Dropdown Documentation:
http://docs.unity3d.com/ScriptReference/UI.Dropdown.html

The following will give you the text from the selected dropdown item:

Debug.Log(EventSystem.current.currentSelectedGameObject.name);

In most cases, you want to get the dropdown value on change. For this Unity recommends adding a listener. So here is an example:

private Dropdown dropDown;

private void Start()
{
    // Fetch the Dropdown GameObject.
    dropDown = GetComponent<Dropdown>();

    // Add listener for when the value of the Dropdown changes, to take action
    dropDown.onValueChanged.AddListener(delegate { DropdownValueChanged(dropDown); });
}

// Display value of the dropdown on change
private void DropdownValueChanged(Dropdown change)
{
    Debug.Log(dropDown.options[dropDown.value].text);
}