zoukankan      html  css  js  c++  java
  • Unity插件之NGUI学习(6)—— 关于Widget怎样加入触发事件(触发OnClick)

    NGUI中,Button本身就带有OnClick事件,可是Sprite,Label等( 也绑有Widget的)并没有触发事件,事实上NGUI的事件触发都必须加入Box Collider,并勾选Is Trigger,在Inspector窗体设置Box大小尺寸,能够在Widget的Collider勾选auto-adjust to match。另一个比較重要的參数须要设置正确,即是UI Root下Camera參数,在Inspector窗体中,要确定UICamera中的Event Type选择3D UI,Event Mask选择Everything。


    然后加入C# Script脚本,

    using UnityEngine;
    using System.Collections;


    public class SpriteClickTest : MonoBehaviour {


    private UISpriteAnimation spriteAnimation; 


    void Start()
    {
    spriteAnimation = GetComponent<UISpriteAnimation>();
    }


    void OnClick() 
    {
    if (spriteAnimation.isPlaying) {
    // 暂停动画
    spriteAnimation.Stop();
    } else {
    // 动画又一次播放
    spriteAnimation.Reset();
    }
    }
    }

    在Inspector窗体



    点击执行游戏,刚才设置在精灵的脚本,就会对应OnClick事件了。


  • 相关阅读:
    高性能JavaScript
    高性能CSS
    去掉超链接文字点击后的灰色框
    高性能HTML
    css整站规划
    css hack 和问题
    IE6支持min-width、max-width CSS样式属性
    WPF草稿
    正则表达式学习日记zz
    详解Adorner Layer(zz)
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/4244808.html
Copyright © 2011-2022 走看看