实现图片的闪烁效果

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

public class TwinkleImg : MonoBehaviour
{
    private Image img;
    private float alpha = 1f;//初始的透明度
    private float f = 1f;//闪烁的速率
    void Start()
    {
        img = GetComponent<Image>();
    }
    void Update()
    {
        if (alpha >= 1f)
        {
            f = -Mathf.Abs(f);
        }
        else if (alpha <= 0f)
        {
            f = Mathf.Abs(f);
        }
        alpha += Time.deltaTime * f;
        img.color = new Color(img.color.r, img.color.g, img.color.b, alpha);
    }
}
原文地址:https://www.cnblogs.com/Cocomo/p/5749767.html