Learn Unity3d from scratch (GUI Chapter 2)

Source: Internet
Author: User

Composite controls are extremely used, Toolbar,selectgrid

Look first:

Toolbar can be seen as a collection of button buttons, one button at a time,

Selectgrid can also be called a collection of toolbar.

The code is as follows:

Using unityengine;using System.collections;public class Gui2:monobehaviour {int toolbarint=0;//represents the default N-1 button is an active string [] toolbarstring={"Tools", "Forms", "help"};//the number of button names and sets int selectgrid=0;string[] selectgridsring = {"Grid 1", "Grid 2", "Grid 3", " Grid 4 "," Grid 5 "};//use Initializationvoid Start () {}//update was called once per framevoid update () {}void on Gui () {toolbarint = GUI. Toolbar (New Rect (0, 0, up, max), Toolbarint, toolbarstring); Selectgrid = GUI. Selectiongrid (New Rect, Selectgrid, selectgridsring, 2),//2 columns, unity can automatically scale//detect if the control has changed if (gui.changed {print ("Some controls have changed");//The specific control click Change if (toolbarint==1) {print ("toolbar1 was clicked");}}}}

Comments are also more complete, the specific do not understand the time can be self-check API.

Learn Unity3d from scratch (GUI Chapter 2)

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.