I don’t know why but i can’t find any information about how to get the text from an InputField in unity, i want to get the text when the user finishes editing the Input field, can someone help please?
My answer is for Unity 4.6 using C#
-
create an InputField and name it whatever you want, let’s say Foo
-
you’ll need a script (can be added to the InputField, but I used a script attached to another object in my project)
-
in that script, in the top line, add
using UnityEngine.UI;
and under public class … addpublic InputField Bar;
(where Bar is the variable name) -
go to Hierarchy and select whichever object has that script attached to it; you will see Bar in the Inspector in the Script section - it will have an empty field to the right of it.
-
Drag your InputField Foo from Hierarchy into that empty field next to Bar
-
Test that it works:
Debug.Log ("Bar = " + Bar.text);
Bar.text = “Success”
Debug.Log ("Bar = " + Bar.text);
Took many hours of trying and watching semi-relevant videos to figure this out.