Change InputField text on ButtonClick


So , I have 4 Buttons and 2 text fields.
And I want to show user different values in this InputFields. (Click first Button - “1” in first inputfield and “2” in second inputfield etc)

(Inputfields in my program it’s just GameObject → UI → InputField)

So , my problem is that I don’t know how to change text in this fields.

I’m adding new function OnClick to each button , but how can I change text in this inputfields?

p.s. Sorry for my bad english.

Hello, If you look carefully you will notice that inside the inputField element in your Hierarchy view as a child name Text.

Ok, so in order to change the InputField text you need to get access to the script that is responsable for showing determinated text in the InputField.

You can Change it by doing something as simple and clean as this:

void ChangeInputFieldText(string message){

		Text textscript = GameObject.Find ("InputField").GetComponentInChildren<Text>(); // This will get the script responsable for editing text
		if(textscript == null){Debug.LogError("Script not found");return;}
		textscript.text = message; // This will change the text inside it
    	void Start(){
    		ChangeInputFieldText("Hello Dude!!");} //Time to call our super awesome function!!

Hope I could help,

Happy New Year