diff --git a/Assets/Scripts/UI/Wait2SecondsToShow.cs b/Assets/Scripts/UI/Wait2SecondsToShow.cs new file mode 100644 index 0000000..9255ff1 --- /dev/null +++ b/Assets/Scripts/UI/Wait2SecondsToShow.cs @@ -0,0 +1,42 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class Wait2SecondsToShow : MonoBehaviour +{ + // Reference to the Image component + private Image canvas; + + private void Start() + { + canvas = GetComponent(); + StartCoroutine(FadeOut(2f)); + } + + // Coroutine to fade out the image + public IEnumerator FadeOut(float duration) + { + // Make sure the canvas is not null + if (canvas == null) + { + yield break; // Exit if canvas is not assigned + } + + // Starting alpha value (1 is fully opaque) + float startAlpha = 1.0f; + + // Elapsed time + float time = 0; + + while (time < duration) + { + time += Time.deltaTime; // Update the time based on the time passed since last frame + float alpha = Mathf.Lerp(startAlpha, 0, time / duration); // Calculate the new alpha value + canvas.color = new Color(canvas.color.r, canvas.color.g, canvas.color.b, alpha); // Apply the new alpha value to the canvas color + yield return null; // Wait for the next frame + } + + Destroy(gameObject); + } +} diff --git a/Assets/Scripts/UI/Wait2SecondsToShow.cs.meta b/Assets/Scripts/UI/Wait2SecondsToShow.cs.meta new file mode 100644 index 0000000..84b62ca --- /dev/null +++ b/Assets/Scripts/UI/Wait2SecondsToShow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 55f8b539d824ad84cb0f7384c2525a2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: