Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Djfeeler on April 02, 2015, 05:42:13 PM

Title: I need help with UIKeyNavigation
Post by: Djfeeler on April 02, 2015, 05:42:13 PM
Hello,

I need help with UIKeyNavigation. I am trying to create a connection panel. I would like the first button is activated when I press the up arrow key on the keyboard. I would like to activate a button with the code. Could you explain me with example code.

Thank you in advance. Djfeeler
Title: Re: I need help with UIKeyNavigation
Post by: Djfeeler on April 02, 2015, 07:08:50 PM
Hello,

I found the answer. I puts the code because if people need it :

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CreateNewAccountFirst : MonoBehaviour {
  5.  
  6.         // Use this for initialization
  7.         void Start () {
  8.        
  9.         }
  10.        
  11.         // Update is called once per frame
  12.         void Update() {
  13.                 if (Input.GetKey (KeyCode.UpArrow)) {
  14.                        
  15.                         if (UICamera.selectedObject == null || !NGUITools.GetActive(UICamera.selectedObject))
  16.                         {
  17.                                 UICamera.currentScheme = UICamera.ControlScheme.Controller;
  18.                                 UIKeyNavigation nav = UIKeyNavigation.list[3];
  19.                                 UIButton btn = nav.GetComponent<UIButton>();
  20.                                 UICamera.selectedObject = btn.gameObject;
  21.                         }
  22.                 }
  23.         }
  24. }

Djfeeler