Showing posts with label unity3d. Show all posts
Showing posts with label unity3d. Show all posts

Monday, August 20, 2018

How to stop an Input field being submitted when it loses focus

The Problem:
In Unity the default behaviour of an input field when it loses focus is to fire the OnEndEdit event.

Solution:
If you don't want this to happen - at the start of the method that is called by OnEndEdit check to see if the enter key is being pressed and return without doing anything is it isn't.

Eg:

if (!Input.GetKey(KeyCode.Return))
  return;