Trying to find what player inputed in Text Input field

I’m trying to find what the player typed in, inside of a text input field and store it in a variable. Can somebody please tell me how to do this?

Hello there,

The easiest way is to use Unity’s built-in events. First, you need to have a script with this function:

private string myVariable = ""; // The variable we want to change based on user input

public void OnFinishInput(string input)
       myVariable = input;

Then, click on your input field in Unity’s Hierarchy. You’ll find a field “OnEndEdit(String)” at the bottom of its Input Field component. Click on the little “+” below it.

Now, drag the object holding the script with the public void we declared above. Click on the dropdown “No Function”, then on the name of your script. Now you see a list of functions you could have this input field call. You’ll notice that “OnFinishInput” is there twice, but you want to select the first one (under “Dynamic String”) if you want live, user-defined input.

Now, whenever you finish entering text into the input field, it will call the function and set “myVariable” to whatever the input is.

I hope that helps!