using UnityEngine; using System.Collections; public class ScoreChecker : MonoBehaviour { public AudioSource winSound; public AudioSource loseSound; public Fader fadeOut; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { } // Update is called once per frame void Update() { } public void resetFader() { Invoke(nameof(checkScore), 0.5f); } private IEnumerator PlayAudioThenActivateGameObject(AudioSource audio, bool showGui) { audio.Play(); if (showGui) { // Activate your GUI here } else { yield return new WaitUntil(() => audio.time >= audio.clip.length); fadeOut.resetFader(); } } void checkScore() { int currentScore = PlayerPrefs.GetInt("CurrentScore"); AudioSource audio = null; bool showGui = false; if (GameSetup.IsHighScore(currentScore)) { audio = winSound; showGui = true; } else { audio = loseSound; } StartCoroutine(PlayAudioThenActivateGameObject(audio, showGui)); } }