Support => NGUI 3 Support => Topic started by: Nerosam on April 14, 2013, 01:14:47 PM
Title: Selecting a button via code?
Post by: Nerosam on April 14, 2013, 01:14:47 PM
Hi folks.
A quick thanks for this awesome unity asset. Works very well.
I have a question. I've spent some hours searching Google and NGUI forums for the answer but cant seem to find it. I have a panel with buttons on it and I want to ad any time be able to call a function which selects a button. For example:-
buttonObject.Select();
I know its possible to have buttons selected by hovering over it but I am trying to implement control pad and/or keyboard support for navigating through the UI.
Any help would be much appreciated.
Title: Re: Selecting a button via code?
Post by: ArenMook on April 14, 2013, 01:36:50 PM
NGUI comes with an example for controller / keyboard input. A main menu driven by controller/keyboard to be precise.
Title: Re: Selecting a button via code?
Post by: Nerosam on April 14, 2013, 04:22:33 PM
NGUI comes with an example for controller / keyboard input. A main menu driven by controller/keyboard to be precise.
Wow....how could I have forgotten about that...thanks for the reminder. Il check it out.
Title: Re: Selecting a button via code?
Post by: p3v1 on June 16, 2013, 12:58:13 AM
I can't get the key functionality to work even if I do it exactly like you have in that controller example (except that I don't use any animations but just change menu states with SetActiveChildren in code). I have main menu and game over menu. For the first time after starting the game key controls works just fine but once I come back to main menu from game over menu, keys just stop working. I change menu statesin code like this:
NGUITools.SetActiveChildren(playUI,false);
NGUITools.SetActiveChildren(gameOverUI,true);
and I have set my Play and Back to Menu buttons StartsSelected to true. I have also tried UICamera.selectedObject = startButton; (Play button) and if I Debug.log that, it is selected but the button doesn't really get selected in the game... What am I doing wrong here?
Title: Re: Selecting a button via code?
Post by: ArenMook on June 16, 2013, 09:49:50 PM