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); } }