unity 使用RawImage实现UI帧动画

2019-11-14  本文已影响0人  菜鸟的笔记
Raw Image组件
先了解下坐标

创建C#脚本,关联到Raw Image组件对象上

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour {

    // 获取Raw Image组件
    private RawImage m_rawImage;

    //增量
    private float m_offsetx;
    private float m_offsety;


    void Start () {
        m_rawImage = GetComponent<RawImage>();
        //计算增量
        m_offsetx = 1 / 4f;
        m_offsety = 1 / 2f;
        StartCoroutine(payAni());
    }


    IEnumerator payAni()
    {
        float x = 0;
        float y = 0;
        while (true)
        {
            y += m_offsety;
            while (x <1)
            {
                x += m_offsetx;
                m_rawImage.uvRect = new Rect(x,y, m_rawImage.uvRect.width, m_rawImage.uvRect.height);
                yield return new WaitForSeconds(0.2f);
            }
            x = 0;
        }
    }
}

修改UV Rect参数

效果(图片不太标准😊)

上一篇下一篇

猜你喜欢

热点阅读