I’m trying to create an input field where the player enters their name and the name is then saved into a variable. I have a canvas setup with an input field, the input field will run a function OnString_PlayerName when the editing is done:
// Player name
private string playerName = "";
// This is run by the input field when done editing
public void OnString_PlayerName()
{
// newPlayer already declared early on
// setPlayerName stores the player name in another script
newPlayer.setPlayerName = playerName;
}
I don’t know how to set the input field to store the text into the playerName variable. Could someone help?
public void OnString_PlayerName(string value)
{
newPlayer.setPlayerName = value;
}
Then you can create a new entry on the “End Edit” Event on the input field and choose the OnString_PlayerName function in the drop down . Make sure to assign the gamobject on that the OnString_PlayerName script is living on to the object field.
I tried using the code provided, but nothing is saved to the variable. I did all the steps you listed, but what I don’t understand is why pass an argument into OnString_PlayerName? Do I need the private playerName variable?
In the inspector of my inputfield, the OnString function has another input field underneath the dropdown menu. The example you supplied doesn’t have such a field in the inspector. Is this normal?
There are 2 types of parameter for the event structur: Dynamic and Static.
Static is what you have currently. You can give a fixed input to the function you are calling.
The dynamic gives you automatically the string that was input into the Input field.
Oh, there are two possible structures. I didn’t see that anywhere in the manual (or I probably looked in the wrong place). It would have been nice to see that there.