I’d like to read configuration data from a text file on the server. I’m using this simple script:
string conf_file = Application.dataPath + "/config.txt";
WWW www = new WWW(conf_file);
float time_start = Time.realtimeSinceStartup;
while (!www.isDone && Time.realtimeSinceStartup < time_start + 5.0f) { };
if (!www.isDone)
return "Could not load '" + conf_file + "'";
else
return www.text;
I’ve done these things from a standalone app without problems, but built as webplayer I keep getting the ‘could not load’ error, whether I run it locally or on a server. The text file is in the same dir as the .unity3d file and is accessible (at least I can open it in the browser).
Replace your download code first. I have an impression that this monster might be blocking it all in web player
while (!www.isDone && Time.realtimeSinceStartup < time_start + 5.0f) { };
Declare IEnumerator in your C# class, like this:
IEnumerator WaitForDownload() {
string conf_file = Application.dataPath + "/config.txt";
WWW www = new WWW(conf_file);
yield return www;
// Now we can access the loaded text
result = www.text;
}
And you need to call this as a coroutine. Place the following line where you need a config request to be made.
StartCoroutine("WaitForDownload");
You'll be able to access the config if you run this on server (and make sure it's accessible by URL from browser).