UI闪烁效果
玩家收到攻击够全屏边缘 出现红色平滑闪烁效果
设置 Raw Image 的color 的 alpha 值 达到效果
public class Blink : MonoBehaviour { static public Blink ins; void Awake() { ins = this; } // Use this for initialization void Start () { StartCoroutine(doBlink()); } // Update is called once per frame void Update () { } // externl interface to blink public void DoBlik() { StopCoroutine(doBlink()); StartCoroutine(doBlink()); } IEnumerator doBlink() { GetComponent<RawImage>().enabled = true; float delta=0.1f; //fade in for (float i = 0; i < 1; i += delta) { yield return new WaitForSeconds(0); GetComponent<RawImage>().color = new Color(1, 1, 1, i); } delta /= 2.0f; //fade out for (float i = 1; i > 0; i -= delta) { yield return new WaitForSeconds(0); GetComponent<RawImage>().color = new Color(1, 1, 1, i); } // for (float i = 0; i < 1; i += delta) // { // yield return new WaitForSeconds(0); // GetComponent<RawImage>().color = new Color(1, 1, 1, i); // } // // // for (float i = 1; i > 0; i -= delta) // { // yield return new WaitForSeconds(0); // GetComponent<RawImage>().color = new Color(1, 1, 1, i); // } GetComponent<RawImage>().enabled = false; } }