🐷
Unityで画面のパネルの点滅エフェクト
Panelの点滅エフェクト
ヒエラルキーで、UI => Panelを作成します。名前を「Effect」にします。以下のプログラムをアタッチしします
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScreenEffectController : MonoBehaviour
{
private GameObject effectObj;
private Image image;
// Start is called before the first frame update
void Start()
{
effectObj = GameObject.Find("Effect");
image = effectObj.GetComponent<Image>();
image.enabled = false;
InvokeRepeating("toggle", 2.0f, 5.0f);
}
private void toggle()
{
StartCoroutine(startFlash());
//image.enabled = image.enabled ? false : true;
}
public IEnumerator startFlash()
{
var wait1 = new WaitForSeconds(0.2f);
var wait2 = new WaitForSeconds(0.2f);
for (int i = 0; i < 2; i++)
{
image.enabled = true;
yield return wait1;
image.enabled = false;
yield return wait2;
}
}
// Update is called once per frame
void Update()
{
}
}
Discussion