using System.Collections; using System.Collections.Generic; using JetBrains.Annotations; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class GameStateController : MonoBehaviour { public Canvas WinLose; public GameObject WinText; public GameObject LoseText; public AudioClip WinClip; public AudioClip LoseClip; public AudioSource source; // Start is called before the first frame update void Start() { source = GetComponent(); } public void WinState() { source.clip = WinClip; source.Play(); StartCoroutine(FadeImage(WinLose.GetComponentInChildren())); WinText.SetActive(true); StartCoroutine(WaitForLoadOut()); SceneManager.LoadScene(0); } public void LoseState() { source.clip = LoseClip; source.Play(); StartCoroutine(FadeImage(WinLose.GetComponentInChildren())); LoseText.SetActive(true); StartCoroutine(WaitForLoadOut()); SceneManager.LoadScene(0); } public IEnumerator FadeImage(Image img) { for (float i = 0; i <= 1; i += Time.deltaTime) { img.color = new Color(0, 0, 0, i); yield return null; } } public IEnumerator WaitForLoadOut() { yield return new WaitForSeconds(5.0f); } // Update is called once per frame void Update() { } }