unity input field on value change code example

Example 1: change the text of inputfield unity

using UnityEngine.UI;

public InputField example; //creates an inputfield with the name "example"
public string textToPutToInputField = "If I helped you don't forget to upvote!"; //creates a string to give its value to the inputfield

public void SetTheText() //creates a void that we can call in one of our main void
{
example.text = textToPutToInputField; //gives the value of our string to the text of the inputfield
}

//Now, it's written "If I helped you don't forget to upvote!" on the inputfield

Example 2: unity inputfield onvaluechanged

//public UI.InputField.OnChangeEvent onValueChanged;
//Accessor to the OnChangeEvent.

using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.

public class Example : MonoBehaviour
{
    public InputField mainInputField;

    public void Start()
    {
        //Adds a listener to the main input field and invokes a method when the value changes.
        mainInputField.onValueChanged.AddListener(delegate {ValueChangeCheck(); });
    }

    // Invoked when the value of the text field changes.
    public void ValueChangeCheck()
    {
        Debug.Log("Value Changed");
    }
}