"OnUserInput" not part of the package?

OnUserInput is not being called from anywhere, unlike the “Terminal.WriteLine” or “ClearScreen”.
I have searched through the other scripts provided with the course, but OnUserInput was not defined in any of those. As a result and as expected, the console isn’t printing any input as it should.

Where exactly is OnUserInput supposed to be defined?

1 Like

Hi. In this part, OnUserInpunt is like ShowMainMenu, and is a function (or Method). The variables, like Terminal.WriteLine and ClearScreen should be defined, but the function no.

var allGameObjects = FindObjectsOfType<MonoBehaviour>();
foreach (MonoBehaviour mb in allGameObjects)
{
    var flags = BindingFlags.NonPublic | BindingFlags.Instance;
    var targetMethod = mb.GetType().GetMethod("OnUserInput", flags);
    if (targetMethod != null)
    {
        object[] parameters = new object[1];
        parameters[0] = input;
        targetMethod.Invoke(mb, parameters);
    }
}

It’s in Terminal.cs, where it’s being called from.

But yeah, you still need…

void OnUserInput(string input) {}

Inside your Hacker.cs file.

This is kinda backwards from what we are used to. You are actually defining the function, not calling it. It’s being called from terminal.cs as shown above, and we are defining what terminal.cs is trying to call. At least that is how I found it to work when I looked into it.

Privacy & Terms