- Home /
How do I show a txt file from my server in GUI?
Hi everyone this is doing my head in, I am new to unity3d (a week or so) and the more I get into it not only the more I love but the harder and harder. ;-)
Anyway I have server side php files that save to txt to display the total visitors as well as the current number visiting, how can I show this within a GUI environment like a HUD.
I have tried loads of different ways and I just can't get my head around it.
Thanks
Answer by Motionreactor · Mar 02, 2010 at 04:14 AM
Luckily the Unity team have made this really simple:
var dataString: String; var url = "http://www.mysite.com/data.txt";
function Start () { // Start a download of the given URL var www : WWW = new WWW(url);
// Wait for download to complete
yield www;
// assign data from URL to string
dataString = www.data;
}
function OnGUI() { GUI.Label(Rect(100, 100, 140, 20), dataString); }
Reference: http://unity3d.com/support/documentation/ScriptReference/WWW.html
Answer by Ashkan_gc · Mar 02, 2010 at 07:11 AM
you can use WWW class to download any resource from the web. you can just get the data and parse/show it yourself or tell unity that it's an audio file and tell it to play the audio. also you can tell it's a video or a package of assets that unity can use in a game. this is one of the powerful features of unity. the code example of MotionReactor is good and complete. also you can use the WWWForm class to send form data to a form in a webpage and submit the form. you can even data fields like images or movies or ...
Answer by Scott 2 · Mar 03, 2010 at 12:05 AM
Thank you everyone
use 'add comment' to add a comment, rather than creating an answer.
Also, if a provided answer fully covers your question, please mark it as accepted by clicking the check mark next to it. That helps people looking for the same answer in the future find it quicker.
Your answer
Follow this Question
Related Questions
How to detect if mouse is over GUI element in Web Player? 0 Answers
Unauthorized use of Caching API in webplayer 0 Answers
WWW fails in Webplayer but not Standalone 0 Answers
How to take a Screenshot that includes GUI 1 Answer
Click button on html page to spawn an object into unity webplayer game 1 Answer