Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Text from UI.InputField?

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

like image 394
kdubey007 Avatar asked Feb 03 '15 06:02

kdubey007


People also ask

How do you use UI in text?

To insert a Text UI element in Unity, right-click on the Scene Hierarchy, then select GameObject -> UI -> Text. There are many properties of the Text element. In which Text Field is the most important property. You can type out what you want the text box to show in that field.


Video Answer


1 Answers

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);
like image 157
maZZZu Avatar answered Sep 18 '22 17:09

maZZZu