-1

basically what I am trying to do is to save information what the user types in the Input Field and displays it it when they press Return instead of the button. Most tutorials use buttons, and not keypress. I prefer it to be in C# Thanks

Johnny
  • 27
  • 7

1 Answers1

1

If you want to call methods/trigger event when a key is pressed, you can do this:

public class ClassA : MonoBehaviour {

void Update() {
        if (Input.GetKeyDown(Keycode.Space))
            // call your method

    }
}

You can read about this here: https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html

  • 1
    `Input.GetKeyDown` is not appropriate to be used with `InputField`. I have a a feeling that OP wants to detect when user is done typing after pressing the Enter/Return key. This should be done by subscribing to the `onEndEdit` event. – Programmer Jan 15 '17 at 10:00