I want to retrieve the text from a UI InputField
but I'm not sure how.
Asked
Active
Viewed 2.8k times
5

Alex Myers
- 6,196
- 7
- 23
- 39

kdubey007
- 310
- 3
- 4
- 9
1 Answers
19
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);

maZZZu
- 3,585
- 2
- 17
- 21
-
6Also dont forget to put `using UnityEngine.UI;` at the top of the script! – izeed Feb 03 '15 at 07:03
-
Awesome I was looking for this as well, thanks @maZZZu! – lakedoo Mar 23 '15 at 15:06
-
What if you have more than 1 input field? – Hola Soy Edu Feliz Navidad Apr 25 '15 at 16:34
-
If you have more than one, you can use `GetComponents` instead of `GetComponent` to get all of them. – maZZZu Apr 25 '15 at 19:18