轮播图(UI渐变替换)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
[RequireComponent(typeof(Image))]
public class Luo_bo : MonoBehaviour
{
    private Image image;
    [Header("轮播精灵")]
    public Sprite[] sprites;
    [Header("轮播时间间隔")]
    public float time=3;

    private bool stop;
    private int number;
    // Start is called before the first frame update
    void Start()
    {
        image = GetComponent<Image>();

        image.sprite = sprites[0];
        StartCoroutine(Lun_bo());
    } 
    IEnumerator Lun_bo()
    {
        while (true)
        {
            if(stop==false)
            {
                stop = true;
                image.sprite = sprites[number];
                yield return new WaitForSeconds(time);
                image.DOFade(0, 0.5f);
                yield return new WaitForSeconds(0.5f);
                number++;
                if (number == sprites.Length)
                {
                    number = 0;
                }
                image.sprite = sprites[number];
                image.DOFade(1, 0.5f);

                yield return new WaitForSeconds(time+0.5f);

                stop = false;
            }
            
        }

    }
}

轮播图(UI渐变替换)

 

上一篇:Linux jar 脚本


下一篇:qt设置渐变色