DCDC25-Dread-Wall/Assets/Scripts/ScreenFadeQuad.cs
Sakib Ahsan 70467f8f1a may 27
2025-05-27 21:42:55 +02:00

26 lines
705 B
C#

using UnityEngine;
using System.Collections;
public class ScreenFadeQuad : MonoBehaviour
{ public float delay = 0f; // seconds before fade starts
public float fadeTime = 2f; // seconds to go from black→clear
Material mat;
void Awake() { mat = GetComponent<MeshRenderer>().material; }
void Start() { StartCoroutine(FadeOut()); }
IEnumerator FadeOut()
{
yield return new WaitForSeconds(delay);
Color c = mat.color;
for (float t = 0; t < 1f; t += Time.deltaTime / fadeTime)
{
c.a = 1f - t;
mat.color = c;
yield return null;
}
gameObject.SetActive(false); // disable when done
}
}