Refactored SceneFader and Presents script

This commit is contained in:
MarcUs7 2024-12-28 22:30:50 +01:00
parent 4077334d05
commit 6f5129ec44
2 changed files with 10 additions and 13 deletions

View file

@ -8,17 +8,14 @@ public class MarcPresents : MonoBehaviour
public string levelToLoad = "Start"; public string levelToLoad = "Start";
public float howMuchToWait = 3.0f; public float howMuchToWait = 3.0f;
private void Start()
// Start is called before the first frame update
void Start()
{ {
StartCoroutine(StartScene()); StartCoroutine(StartScene());
} }
IEnumerator StartScene() private IEnumerator StartScene()
{ {
yield return new WaitForSeconds(howMuchToWait); yield return new WaitForSeconds(howMuchToWait);
sceneFader.FadeTo(levelToLoad); sceneFader.FadeTo(levelToLoad);
} }
} }

View file

@ -8,37 +8,37 @@ public class SceneFader : MonoBehaviour {
public Image img; public Image img;
public AnimationCurve curve; public AnimationCurve curve;
void Start () private void Start ()
{ {
StartCoroutine(FadeIn()); StartCoroutine(FadeIn());
} }
public void FadeTo (string scene) public void FadeTo(string scene)
{ {
StartCoroutine(FadeOut(scene)); StartCoroutine(FadeOut(scene));
} }
IEnumerator FadeIn () private IEnumerator FadeIn ()
{ {
float t = 1f; var t = 1f;
while (t > 0f) while (t > 0f)
{ {
t -= Time.deltaTime; t -= Time.deltaTime;
float a = curve.Evaluate(t); var a = curve.Evaluate(t);
img.color = new Color (0f, 0f, 0f, a); img.color = new Color (0f, 0f, 0f, a);
yield return 0; yield return 0;
} }
} }
IEnumerator FadeOut(string scene) private IEnumerator FadeOut(string scene)
{ {
float t = 0f; var t = 0f;
while (t < 1f) while (t < 1f)
{ {
t += Time.deltaTime; t += Time.deltaTime;
float a = curve.Evaluate(t); var a = curve.Evaluate(t);
img.color = new Color(0f, 0f, 0f, a); img.color = new Color(0f, 0f, 0f, a);
yield return 0; yield return 0;
} }