Last active
November 4, 2017 22:53
-
-
Save oismaelash/7858666c3921f326079200e7d749140b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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