Search code examples
c#unity-game-engine

Why am I not able to select the function from the inspector?


I'm making a Wordle game and need to add an "on end edit" function to an input field that i have in the game. However, i simply cannot add it.

public void ReadStringInput(string s, string word)
{
    input = s;

    firstLetterWord = word.Substring(0, 1);
    secondLetterWord = word.Substring(1, 1);
    thirdLetterWord = word.Substring(2, 1);
    fourthLetterWord = word.Substring(3, 1);
    fifthLetterWord = word.Substring(4, 1);

    firstLetterInput = input.Substring(0, 1);
    secondLetterInput = input.Substring(1, 1);
    thirdLetterInput = input.Substring(2, 1);
    fourthLetterInput = input.Substring(3, 1);
    fifthLetterInput = input.Substring(4, 1);

    Debug.Log(firstLetterInput + " " + firstLetterWord);

    if (firstLetterWord == firstLetterInput)
    {
        Debug.Log("first letter correct");
    }
}

There's a different function in that script that looks about the same and i can add that one.

public void ChooseWord()
{
    Random random = new Random();

    string word =  dictionary[random.Next(dictionary.Length)];

    Debug.Log(word);
}

I tried making new functions and those i can select. I have no idea why this is happening, so i tried searching it up and couldn't find anything like this. I'm selecting the object that has the script, and can even select functions of that script (e.g. ChooseWord), but can't select that single one.

enter image description here


Solution

  • onEndEdit function in Unity can work only with functions that have maximum of one argument. This argument will be set to the input's value.

    so just use one argument in your function that you are trying to call.

    public void ReadStringInput(string value)