- Home /
Read text from http
Hi all,
I have:
public TextAsset ttt;
void OnGUI(){
GUI.TextArea(new Rect(600,10,350,300),ttt.text,style_text);
}
I already have hosting anf file txt http://host.com/fff.txt
My question is: how can I read this file online and put in TextArea?
Comment
Answer by AXXE78 · Aug 03, 2013 at 03:52 PM
using UnityEngine;
using System.Collections;
public class DownloadText : MonoBehaviour
{
private string textFromWWW;
private string url = ""; // <-- enter your url here
void Start ()
{
StartCoroutine(GetTextFromWWW());
}
void OnGUI()
{
GUI.Label(new Rect(0, 0, 200, 200), textFromWWW);
}
IEnumerator GetTextFromWWW ()
{
WWW www = new WWW(url);
yield return www;
if (www.error != null)
{
Debug.Log("Ooops, something went wrong...");
}
else
{
textFromWWW = www.text;
}
}
}
AXXE78 thank you that's work graet but I have only one question, in unity I use TextArea as rich text (I can use tags) but how can I write sub index? example in html 453 is it passible?
I think you have to parse HT$$anonymous$$L content into Unity by yourself, I don't know of any ready-to-use solutions, but try googling and you'll find something. For example, have a look at this: http://forum.unity3d.com/threads/133566-HT$$anonymous$$L-Renderer