找回密码
 立即注册
查看: 6494|回复: 85

[脚本] NGUI 播放序列图

[复制链接]
发表于 2015-1-20 18:17 | 显示全部楼层 |阅读模式
今天在蛮牛教育上学习了如何使用NGUI做序列帧动画
1. 新建一个场景,新建一个2D UI ,在Panel节点下新建一个UISpirit,图片选择序列帧的第一帧图片。
2.如何让Spirit动态换图片,是我们要解决的重要问题。只要UIspirit能够根据时间动态的换图片就可以做到播放序列帧动画。其实很简单,最重 要的就是UISpiritName属性。我们只要能够动态改变UISpiritSpiritName,就可以实现动态换图的功能。
代码如下
public bool ActivateWait = false;
    float fireRate = 0.2f;
    int i = 0;
    float nextFire;
    string[] ActivatorTexture = new string[] { "activity00", "activity01", "activity02", "activity03", "activity04", "activity05", "activity06", "activity07", "activity08", "activity09", "activity10", "activity11" };     
    void Awake()
    {
        this.GetComponent<UISprite>().enabled = false;
    }
    // Use this for initialization
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
        if (ActivateWait)
        {
            this.GetComponent<UISprite>().enabled = true;
            if (i < ActivatorTexture.Length)
            {
                if (Time.time > nextFire)
                {
                    nextFire = Time.time + fireRate;
                     this.GetComponent<UISprite>().spriteName= ActivatorTexture;
                    i++;
                }
            }
            else
            {
                i = 0;
            }
        }
        else
        {
            this.GetComponent<UISprite>().enabled = false;
        }
    }

发表于 2017-2-10 08:38 | 显示全部楼层
很不错
发表于 2017-2-10 08:07 | 显示全部楼层
楼主是超人
发表于 2017-2-10 08:05 | 显示全部楼层
好帖就是要顶
发表于 2017-2-10 08:17 | 显示全部楼层
很好哦
发表于 2017-2-10 08:26 | 显示全部楼层
不错不错
发表于 2017-3-2 07:27 | 显示全部楼层
很不错
发表于 2017-3-2 07:57 | 显示全部楼层
好帖就是要顶
发表于 2017-3-2 07:07 | 显示全部楼层
顶顶多好
发表于 2017-3-2 07:19 | 显示全部楼层
真心顶
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 10:04 , Processed in 0.150643 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表