Unity 4.6 Ugui Click events

Source: Internet
Author: User

Because the Unity 4.6 has just released, the Ugui function of the relevant data is not very perfect, today just installed Unity 4.6, want to see if Ugui is good, then start learning today Ah!

1, create a new empty project.

2, open Unity's own UI system.

3, create Ui->canvas. Here I do not introduce more canvas, plainly is the layout. You'll find a lot more EventSystem (event System).

1,eventsystem is an object that sends input-based events to an application, whether it's a keyboard, mouse, touch, or custom input.

2,EventSystem consists of several components that send events.

Detailed introduction See: http://docs.unity3d.com/460/Documentation/ScriptReference/EventSystems.EventSystem.html

4, Next we build a panel (also not built, personal preferences), build a panel I feel easy to manage the space.

5, then get a button out, OK!

Suspension Effect:

5, Next we write a script to experiment with click events.

Method One:

usingUnityengine;usingSystem.Collections;usingUnityengine.ui; Public classtestclick:monobehaviour{//Use this for initialization    voidStart () {Button btn= gameobject.getcomponent<button>();Btn.onClick.AddListener (click); }        voidClick () {Debug.Log ("Mouse Click"); }}

Implementation results:

Method Two:

Experimental results:

It's not hard at all!

Let's learn a little bit further:

6, build a ButtonClick.cs

usingUnityengine;usingSystem.Collections;usingUnityengine.ui;usingunityengine.events; Public classButtonclick:monobehaviour {//Use this for initialization    voidStart () {Button btn= gameobject.getcomponent<button>();Btn.onClick.AddListener (Delegate()            {                 for(intI=0;i<Ten; i++) {OnClick (i);    }            }); }     Public voidOnClick (intindex)    {Debug.Log (index); }}

Experimental results:

is not commissioned can also use Ah, good, now learn to sell, we learn together!

Unity 4.6 Ugui Click events

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.