using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DownloadImage : MonoBehaviour { public string namesresources; public bool renderer = true, audio = false; void Awake() { if (audio) { StartCoroutine(WaitForAudios()); } else { StartCoroutine(WaitForImages()); } } IEnumerator WaitForAudios() { while (!GamesResourcesFinder.instance || GamesResourcesFinder.instance.gameReady == false) { yield return new WaitForEndOfFrame(); } Debug.Log("Downloaded"); AudioSource audioS = GetComponent(); AudioClip clipToUse = GamesResourcesFinder.instance.AskForAudio(namesresources); yield return new WaitForSeconds(.5f); Debug.Log(clipToUse.name); audioS.clip = clipToUse; yield return new WaitForEndOfFrame(); while (!audioS.isPlaying) { audioS.Play(); yield return new WaitForEndOfFrame(); } Destroy(this); } IEnumerator WaitForImages() { while (GamesResourcesFinder.instance.gameReady == false) { yield return new WaitForEndOfFrame(); } if (renderer) { GetComponent().sprite = GamesResourcesFinder.instance.AskForImage(namesresources); } else { GetComponent().sprite = GamesResourcesFinder.instance.AskForImage(namesresources); } Destroy(this); } }