Skip to content

Instantly share code, notes, and snippets.

@oismaelash
Last active November 4, 2017 22:53
Show Gist options
  • Save oismaelash/7858666c3921f326079200e7d749140b to your computer and use it in GitHub Desktop.
Save oismaelash/7858666c3921f326079200e7d749140b to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Networking;
public class TextLoader : MonoBehaviour
{
public string url = "http://www.dominio.com/arquivo.txt";
public Text textUI;
public bool isLoaded = false;
// Use this for initialization
void Start()
{
StartCoroutine(LoadText());
}
public IEnumerator LoadText()
{
using (UnityWebRequest www = UnityWebRequest.Get(url))
{
yield return www.Send();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("www returned");
textUI.text = www.downloadHandler.text;
isLoaded = true;
Debug.Log(www.downloadHandler.text);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment