- Home /
Getting the text from UIInput
I have an area for the user to enter their name, which I then want to store for later usage. To do this I have a UIInput called 'NameInput' which has a label called 'label' that should hold the name they have entered.
I'm pretty new with Unity so I have no idea how I would go about getting the text in the label. I know that I need to use GetComponent (i think) but I'm not sure on how to use it. Does anyone have a nice example I can use for C# or if you could post the code with an explanation of how to get it that would be great.
Answer by GerryM · Feb 06, 2013 at 08:28 PM
There are several ways, the most easy on probably is using the text component of UIInput, like:
string textYouTyped = myInputField.GetComponent<UIInput>().text;
Where myInputField does reference the input widget.
Also, check the official NGUI forum where you'll find more on this specific plugin.
add a public transform variable to your script and drag the input field onto it.
public transform myInputField;
But here, the user must hit the return key in order to save the text right? Can we change it to autosave? Here in the attached picture, the user will enter the name and when he click Submit(without hitting Enter key), the text should save. Is it possible?(I'm using 2.7 ngui)
EDIT: Solved it. It was the problem of storing the value in another variable. If I used the UIInput text property directly from the GetComponent method to feed to the button, the text is autosaved.
Not removing this comment in case anybody arrives at the same problem.
Your answer
Follow this Question
Related Questions
Checking whether string is a valid Input.Key 1 Answer
imeCompositionmode 0 Answers
Gui list and color 0 Answers
Display "organized" string on GUI Label 1 Answer
NGUI countdown in label 0 Answers