How to get Text from UI.InputField?

kdubey007 picture kdubey007 · Feb 3, 2015 · Viewed 25.8k times · Source

I want to retrieve the text from a UI InputField but I'm not sure how.

Answer

maZZZu picture maZZZu · Feb 3, 2015

You can do it by first getting reference to the gameObject somehow then getting the InputField component from it and taking the component's text variable:

    GameObject inputFieldGo = GameObject.Find("PathToTheGameObject");
    InputField inputFieldCo = inputFieldGo.GetComponent<InputField>();
    Debug.Log(inputFieldCo.text);