NGUI tutorial (2) use NGUI to create a 2D scenario and Add labels and buttons, ngui2d

Source: Internet
Author: User

NGUI tutorial (2) use NGUI to create a 2D scenario and Add labels and buttons, ngui2d
1. Create a 2D scenario
To use NGUI to create a 2D scenario, we must first create a new project and import NGUI as the plug-in for this project. I believe that if we have read the previous tutorial and know how to import NGUI, we will not go into details here, if you have any questions, go to the previous tutorial. Here I have imported it successfully. The NGUI menu is displayed in the menu.

On the project panel, you can see the folder with NGUI

Next we can click [NGUI] --> [Create] --> [2D UI] in the menu. After the creation is successful, we can see an additional UI Root in the Hierarchy panel.

Click UI Root and you will see a Camera under the UI Root.


In this case, there are two cameras in one scenario. we delete Main Camera and there is only one UIRoot and Camera in the Hierarchy Panel. This is a 2D scenario. Save this scenario. First, create a folder under the Assets folder and name this folder example.

In the menu, choose File> Save Scene to Save the scenario and name it e01 in example. In this way, the e01 File is added to the example folder.



2. Create a Panel
To add labels and buttons to a scene, you must first have a container to hold these components. Therefore, create a new Panel. On the Hierarchy Panel, select Camera and click NGUI> Create> Panel in the menu to Create a Panel.


3. Create a Label and a Button

Click NGUI> Open> Widget Wizard to bring up the Widget Tool panel.


However, the Add To button is gray at this time, so you cannot Add Atlas and Font To the Widget Tool. In this way, the Add To button becomes green and clickable.

Select Label in the Template, select Panel next To the Add To button, and click Add To generate a Label under the Panel.
Select "Button" in "Template" and "Add To" next To "Panel". If no gallery is specified in "Altas", "Add To" is dimmed. Click the Atlas drop-down menu and select an Atlas. Here we select Wooden Atlas,

Click Add To generate a Button.



However, we can see that only text and no image are displayed in the Button. You need to specify an image for the Button's Background and click the Button to select the Background. In the Inspector panel, click UISprite (scrpit) and a selection page will pop up.

Select Wooden Background and the button will have a Background. But the Label and Button overlap, just move their positions.


How to convert the NGUI button from 2D to 3D in Unity

The switching scenario has nothing to do with 2D and 3D. Do you not add the required scenario in build setting?
 
Unity3d uses NGUI309. How can I create a button?

Menu-NGUI-Create-Button/ImageButton.

Then add the boxcollider component to receive events.
Select Button-menu-NGUI-Attch-Collider

Then you can create a script and write an OnClick method.

Void OnClick (){
Debug. Log (this. name );
}

Bind the script to the NGUI Button you just created.
Click the Button to output the name of the Button.

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.