Book Image

Learning NGUI for Unity

By : Charles Bernardoff (EURO)
Book Image

Learning NGUI for Unity

By: Charles Bernardoff (EURO)

Overview of this book

Table of Contents (17 chapters)
Learning NGUI for Unity
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Keyboard keys


In this section, we'll see how to add keyboard control to our UI. First, we'll see how to bind keys to buttons, and then we'll add a navigation system using keyboard arrows.

UIKey binding

The UIKey Binding component assigns a specific key to the widget it's attached to. We'll use it now to assign the keyboard's Escape key to our menu's Exit button:

  1. Select our UI Root | Main | Buttons | Exit GameObject.

  2. Click the Add Component button in the Inspector view.

  3. Type key with your keyboard to search for components.

  4. Select Key Binding and hit Enter or click on it with your mouse.

Let's see its available parameters.

Parameters

We've just added the following UIKey Binding component to our Exit button, as follows:

The newly attached UIKey Binding component has three parameters:

  • Key Code: Which key would you like to bind to an action?

  • Modifier: If you want a two-button combination. Select on the four available modifiers: Shift, Control, Alt or None.

  • Action: Which action should we bind to this key...