Catch InputField text

I’m doing a registration to my game and I want to get the string of InputField and send to somewhere, Its my first time on the new UI,

I want to send this when I click on the UI.Button.

Searching on the OnClick() function of the button I dont found nothing to catch that, have some specific function for this or I need to scrippting ?

I’m scripting the code and I put that inside Button the problem is the field is comming blank on SendString print:

public class OnClickButtonReg : MonoBehaviour 
{
	[SerializeField]
	private Button sendButton = null;
	public GameObject boxName;
	string fulano;
	
	// Use this for initialization
	void Start () 
	{
		print("vai");
		fulano = boxName.GetComponent<Text>().text;
		sendButton.onClick.AddListener(delegate {
		SendString(fulano);
		
	});
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void SendString(string vaiFilhao)
	{
		print(vaiFilhao);
	}
}

There are a few ways to do this, here are some easy ones:

  • Don’t use a button… just wire up the receiving function via the End Edit event. Note that this will trigger even if no change has been made.
  • Create a script on the InputField with a public void Submit() function. Use GetComponent in this script to get the InputField. The .text field has the input string so trigger whatever action you want on submission here. Use the inspector in the editor to wire up the buttons OnClick event to the InputField and it’s Submit method.