x


Lock "actions" while we write in GUI objects

Is there any way to avoid activate actions throw Input.getKey or Input.whatever while the user is writing on a GUI Object like TextField or TextArea?

For example, I don't want to move my character with W A S D if I press this keys in a text field.

Thanks for all!

more ▼

asked Jun 16 '10 at 01:31 PM

SeRoX gravatar image

SeRoX
57 6 6 12

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You can use Input.ResetInputAxes() every frame that you're typing, though that doesn't work too well if you're using FixedUpdate - it'll still move every so often (when there is more than one fixedupdate in a frame)

Better way would be to store that you're typing, and your other scripts to check with a static bool somewhere for if they're allowed to move

more ▼

answered Jun 16 '10 at 02:04 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

I tried this solution and it works pretty well. I don't know if with more complex situacions would work fine but, to avoid the movement of the character, it works.

Jun 17 '10 at 12:58 AM SeRoX
(comments are locked)
10|3000 characters needed characters left

http://answers.unity3d.com/questions/8/if-i-have-a-button-over-my-3d-world-how-can-i-detect-if-a-mouseclick-was-in-the/69#69

You can apply the same kind of logic to button presses. You just need to check to see if your text field has focus, and if so early out of your key input events.

more ▼

answered Jun 16 '10 at 02:36 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

(comments are locked)
10|3000 characters needed characters left

Not sure if this will work, but did you try Event.current.Use() after you detected they typed in your text field in the OnGUI function?

more ▼

answered Jun 16 '10 at 01:42 PM

NZRoadKill gravatar image

NZRoadKill
137 2 3 8

That won't work, no

Jun 16 '10 at 02:04 PM Mike 3
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3682
x953
x125

asked: Jun 16 '10 at 01:31 PM

Seen: 1255 times

Last Updated: Jun 16 '10 at 01:31 PM