using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ScreenFlash : MonoBehaviour { Image screenFlashImage; // Start is called before the first frame update void Start() { this.screenFlashImage = transform.GetComponentInChildren(); screenFlashImage.color = new Color(1.0f, 0.0f, 0.0f, 0.5f); } private void OnEnable() { if (screenFlashImage != null) screenFlashImage.color = new Color(1.0f, 0.0f, 0.0f, 0.5f); } // Update is called once per frame void Update() { screenFlashImage.color = new Color(1.0f, 0.0f, 0.0f, screenFlashImage.color.a - (0.5f * Time.unscaledDeltaTime)); if (screenFlashImage.color.a <= 0.0f) { this.gameObject.SetActive(false); } } }