Simple button for creating unity basic ngui plug-in

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.