Unity version: 4.5.1 ngui version: 3.6.5
Note that most of the online tutorials for ngui are 2.x, which is slightly different in the steps above. This article is suitable for beginners.
Example:
Create a background and button through ngui.
1. Create a new scenario and save it. In this scenario, name it test:
On the main interface of unity: file-new scene, and then save the scenario. File-save scene as .. Here, the scenario is named test, and the following effects can be seen in Unity:
2. most of the tutorials on the Internet are about to delete the built-in camera in the scenario, that is, the "Main camere" shown in the left-side figure above. However, if you do not delete the camera, you can see the effect, here you are free to choose. Next, you can use ngui to create an instance:
Ngui -- create -- 2D UI:
You can see the following results:
3. Select camera under UI root, create anchor through ngui -- create -- anchor, and add a panel under anchor:
The effect is as follows:
5. Next, add the button Background:
Open widger Wizard:
On the page, click Add to finish to set the background:
6. At this time, create a C # script to respond to the button clicking:
The Code is as follows:
using UnityEngine;using System.Collections;public class BtnClick : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnClick() { Debug.Log ("xx"); }}Btnclick
Add the sprite value. You can see that "click button" is not displayed when you click it;
7. manually add a collision generator for the button:
Select Sprite and create a collision generator:
Then you can test it again. When you click the button, the word "click" appears.
8. You can create a label for the button and add a label to the sprite through the widger wizard. You can modify the font size and color:
9. Complete a simple button with the following effect: