UP-Viagg-io/Viagg-io/Assets/WorldSpaceSlideshow.cs
2025-05-21 11:04:45 +02:00

60 lines
1.6 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class WorldSpaceSlideshow : MonoBehaviour
{
public Texture[] images; // Assign your 5 images here
public float fadeDuration = 1.5f; // Duration of fade
public float displayDuration = 3f; // How long each image is shown
private RawImage rawImage;
private int currentIndex = 0;
private int nextIndex = 1;
private float alpha = 0f;
private void Start()
{
rawImage = GetComponent<RawImage>();
rawImage.color = new Color(1, 1, 1, 0);
StartCoroutine(Slideshow());
}
IEnumerator Slideshow()
{
while (true)
{
Texture currentTex = images[currentIndex];
Texture nextTex = images[nextIndex];
// Fade in current image
rawImage.texture = currentTex;
yield return Fade(0, 1);
// Wait while image is fully visible
yield return new WaitForSeconds(displayDuration);
// Fade out current image
yield return Fade(1, 0);
// Prepare next indices
currentIndex = nextIndex;
nextIndex = (nextIndex + 1) % images.Length;
}
}
IEnumerator Fade(float from, float to)
{
float t = 0;
while (t < fadeDuration)
{
t += Time.deltaTime;
float normalized = t / fadeDuration;
alpha = Mathf.Lerp(from, to, normalized);
rawImage.color = new Color(1, 1, 1, alpha);
yield return null;
}
rawImage.color = new Color(1, 1, 1, to);
}
}