NGUI 播放序列帧特效

这是一个Unity脚本示例,用于实现技能按钮的动画效果。通过播放一系列的纹理图像来模拟动画,该脚本定义了一个名为SkillButtonAnim的公共类,继承自MonoBehaviour。它包括了动画播放的控制逻辑、纹理数组的定义以及UI精灵组件的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

脚本:

public class SkillButtonAnim : MonoBehaviour {
    /*
     * 播放序列帧
     * 
     */
    public UIAtlas atlas;
    public bool PlayAnim = false;
    [Range(0,0.1f)]
    public float fireRate = 0.1f;
    int i = 0;
    float nextFire;
    string[] ActivatorTexture ;
    void Awake()
    {
    }
    // Use this for initialization
    void Start()
    {
        ActivatorTexture = atlas.GetListOfSprites().ToArray();
     
        GetComponent<UISprite>().atlas = atlas;
        this.GetComponent<UISprite>().spriteName = ActivatorTexture[0] ;
        
    }
    // Update is called once per frame
    void Update()
    {
        if (PlayAnim)
        {
            if (i < ActivatorTexture.Length)
            {
                if (Time.time > nextFire)
                {
                    nextFire = Time.time + fireRate;
                    this.GetComponent<UISprite>().spriteName = ActivatorTexture[i];
                    i++;
                }
                if (i==ActivatorTexture.Length-1)
                {
                    PlayAnim = false;
                }
            }
            else
            {
                i = 0;
            } 
        }
        else
        {
            if(!this.GetComponent<UISprite>().spriteName.Equals(ActivatorTexture[0]))
            this.GetComponent<UISprite>().spriteName = ActivatorTexture[0];
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值