using UnityEngine; using UnityEngine.UI; public class StartFade : MonoBehaviour { private Image imageComponent; // Referencja do komponentu Image public float initialDelay = 4.0f; // Czas trwania pełnej czerni public float fadeDuration = 3.0f; // Czas trwania zanikania private float timeElapsed = 0f; private bool startFading = false; void Start() { // Pobieramy komponent Image z GameObject imageComponent = GetComponent(); if (imageComponent == null) { Debug.LogError("No Image component found on this GameObject."); return; } // Ustawiamy początkowy kolor na czarny z pełną przezroczystością (alpha = 1) imageComponent.color = new Color(0, 0, 0, 1); } void Update() { timeElapsed += Time.deltaTime; if (!startFading) { if (timeElapsed >= initialDelay) { startFading = true; timeElapsed = 0f; // Resetujemy czas do śledzenia fade-in } } else { if (timeElapsed <= fadeDuration) { // Obliczamy nową wartość alpha, zmniejszając ją do 0 float alpha = Mathf.Lerp(1, 0, timeElapsed / fadeDuration); imageComponent.color = new Color(0, 0, 0, alpha); } else { // Upewniamy się, że alpha jest ustawiona na 0 i wyłączamy obiekt imageComponent.color = new Color(0, 0, 0, 0); gameObject.SetActive(false); // Wyłączamy GameObject po zakończeniu fade-in } } } }