41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class Blink : MonoBehaviour
|
|
{
|
|
public float blinkSpeed = 5;//闪烁速度
|
|
private float timer;//计时器
|
|
public float timeval = 1;//时间间隔
|
|
private Image img;//指向自身图片
|
|
public bool isAddAlpha;
|
|
private void Start()
|
|
{
|
|
img = GetComponent<Image>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
timer += Time.deltaTime;
|
|
if (isAddAlpha)
|
|
{
|
|
img.color += new Color(0, 0, 0, Time.deltaTime * blinkSpeed);
|
|
if (timer >= timeval)
|
|
{
|
|
img.color = new Color(img.color.r, img.color.g, img.color.b, 1);
|
|
isAddAlpha = false;
|
|
timer = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
img.color -= new Color(0, 0, 0, Time.deltaTime * blinkSpeed);
|
|
if (timer >= timeval)
|
|
{
|
|
img.color = new Color(img.color.r, img.color.g, img.color.b, 0);
|
|
isAddAlpha = true;
|
|
timer = 0;
|
|
}
|
|
}
|
|
}
|
|
} |