Author Topic: [solved] How to lose the focus from a UIButton after click?  (Read 4284 times)

ninuson

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 2
    • View Profile
[solved] How to lose the focus from a UIButton after click?
« on: October 13, 2014, 08:56:29 PM »
Hi,

First of all, thanks for a wonderful package! I've been working with it for a while and both the number of features and the support are outstanding.

I ran into something I couldn't find either on the forums or figure out myself. I mix both Unity's native input system and NGUI. I know that it's not ideal and hopefully will refactor everything to NGUI eventually, but I would prefer to solve this problem regardless.

To my problem: I have some things key bound to happen when Input.GetKey(KeyCode.Return) is happening. Specifically, it activates the chat logic. My problem is that if I have clicked on any of the NGUI buttons on the GUI, hitting enter will also click that button. I did not define a behavior for when a key is pressed on the NGUI side for any of the buttons and I don't have an OnSubmit() or KeyBind scripts attached to anything. This sort of leads me to believe it's some default behavior I'm simply not aware of...

I have also tried to play around with UIInput but I wasn't sure how to clear the current "focus". Help would be appreciated!
« Last Edit: October 16, 2014, 04:51:46 PM by ninuson »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to lose the focus from a UIButton after click?
« Reply #1 on: October 14, 2014, 02:06:24 PM »
This happens because when you touch something with NGUI, it gains selection. Selected objects receive keyboard and navigation events, and Return key is one of them.

UICamera.selectedObject = null;