其他分享
首页 > 其他分享> > 轮播图(UI渐变替换)

轮播图(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;
            }
            
        }

    }
}

 

标签:轮播,stop,渐变,0.5,number,sprites,UI,using,image
来源: https://blog.csdn.net/fanfan_hongyun/article/details/120484005