57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
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<Image>();
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
}
|