ShantiManti/Assets/game/Scripts/UI_start/SceneFader.cs
2024-04-28 13:51:52 +02:00

49 lines
747 B (Stored with Git LFS)
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
public class SceneFader : MonoBehaviour {
public Image img;
public AnimationCurve curve;
void Start ()
{
StartCoroutine(FadeIn());
}
public void FadeTo (string scene)
{
StartCoroutine(FadeOut(scene));
}
IEnumerator FadeIn ()
{
float t = 1f;
while (t > 0f)
{
t -= Time.deltaTime;
float a = curve.Evaluate(t);
img.color = new Color (0f, 0f, 0f, a);
yield return 0;
}
}
IEnumerator FadeOut(string scene)
{
float t = 0f;
while (t < 1f)
{
t += Time.deltaTime;
float a = curve.Evaluate(t);
img.color = new Color(0f, 0f, 0f, a);
yield return 0;
}
SceneManager.LoadScene(scene);
}
}