Unity Plugin Ngui Learning (6)--about how widgets add trigger events

Source: Internet
Author: User

Ngui, the button itself with the OnClick event, but Sprite,label (also tied with the widget) does not trigger the event, in fact Ngui event trigger must add box Collider, and tick is Trigger, To set the box size size in the inspector window, you can tick auto-adjust to match in the Widget's collider. There is also a more important parameter that needs to be set correctly, that is UI root under the camera parameter, in the inspector window, to determine the Event type in Uicamera select the 3D ui,event mask selection everything.


Then add a C # script script,

Using Unityengine;
Using System.Collections;


public class Spriteclicktest:monobehaviour {


Private Uispriteanimation spriteanimation;


void Start ()
{
Spriteanimation = getcomponent<uispriteanimation> ();
}


void OnClick ()
{
if (spriteanimation.isplaying) {
Pause Animation
Spriteanimation.stop ();
} else {
The animation plays back
Spriteanimation.reset ();
}
}
}

In the Inspector window



Click Run game, just set in the wizard script, will be the corresponding OnClick event.


Unity Plugin Ngui Learning (6)--about how widgets add trigger 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.