Purpose of OnUserInput()

I am a bit confused on what this line of code actually does. Does it respond to what the user is typing? Does it store this information?

Also when is this function called? Just when the user types?

This is what my code looks like inside of OnUserInput(string input) since I was playing around, but it makes no difference: print(“Hello” + input); It never prints the Hello. Is there something that I am missing or not understanding?

Also if this is just printing what I type and I remove the code, it stills show what I type, so what is it doing exactly?

Hi Joseph,

“On” indicates that the method is part of some event system. In our case, the event is “when the user typed something and pressed ‘return’”. Ben’s and Rick’s “secret” code processes the user input and passes it on as a string to your OnUserInput method. The parameter of that method is named input, thus the data gets assigned to input. Try to rename input. That works as well.

The print method logs a message into your Unity console, which is not the fancy 3D console in your scene.


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms