I wanted to download a text from Pastebin(raw) into a texfile.
I created an IEnumerator
, but somehow it just creates an empty text file.
public IEnumerator DownloadTextFile()
{
WebClient version = new WebClient();
yield return version;
version.DownloadFileAsync(new Uri(myLink), "version.txt");
}
public IEnumerator DownloadTextFile()
{
WebClient version = new WebClient();
yield return version;
version.DownloadFile(myLink , "version.txt");
}
Thanks in advance.
WebClient is not designed to be used from within Unity3D like that,
yield return version;
does not wait for the file to be downloaded.What you could do is use the
WWW
class and perform the download that way.WWW
is part of Unity and is designed to work in ways with the way Unity works.Be sure to start the DownloadTextFile by calling
StartCoroutine(DownloadTextFile())