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

Player name display


Let's see how to display the player's stored name above the character. It will look like this:

Player name displayed above character

In order to display this name label, we'll need to configure the 2D UI Root element that will only render 2D UI elements and make sure it follows the player.

In-game 2D UI root

We'll now add some in-game 2D user interface elements attached to 3D world objects. Let's create a new 2D UI root element that will be used exclusively for in-game 2D UI:

  1. Create a new 2D UI element by navigating to NGUI | Create | 2D UI.

  2. Select the new UI Root (2D) GameObject in the hierarchy.

  3. Rename it to InGame2DUI.

  4. For its attached UIRoot component:

    • Change Scaling Style to Constrained .

    • Set Content Width to 1920.

    • Set Content Height to 1080.

    • Leave its height's Fit option checked.

Now, let's create a new layer to hold all 2D UI elements:

  1. Navigate to Edit | Project Settings | Tags and Layers.

    Tip

    You can also click on the Layers drop-down list in the top-right corner of the Unity...