- Home /
How to read and rewrite text files on a local host with WebGL?
Hi guys,
I'm making a game where the levels are generated by several parameters, which are saved on an external text file. The user's choices in the game are saved as numbers on a second text file.
I'm using C#, and call these files with (for example):
string fileName1 =
Application.dataPath + @"\TempVars.txt";
string fileData = System.IO.File.ReadAllText(fileName1);
And it works perfectly on a PC build. But, I need this game on the web, and that's where I'm stuck. I understood that I need to use the WWW class in order to call these file on a host, but I can't figure out how to use it. (I'm trying it on a local host, and I can't seem to turn the www class to a string or to reverse the process)
Can someone please explain to me how exactly to READ and REWRITE text files, that are on the local host with the webplayer? Or at least refer for a good guide on how to it.
Thanks!
got the same problem.
maybe this one can help http://stackoverflow.com/questions/34116366/editorutility-openfilepanel-for-unity-webgl-runtime
It is bad practice to use text files for such a thing, because you have to parse the data back in. It is better to use proper serialization methods. I know this doesn't answer your question, but I believe even webplayer uses Application.persistentDataPath. Don't quote me on that though. Still, you have to use the WWW which is essentially like the web version of System.IO.
Also, if you want a quick way, PlayerPrefs works too.
Your answer
Follow this Question
Related Questions
File Paths to load files with WWW for WebGL 0 Answers
Is there a way to load resources with unkown case (.png/.PNG) using www objects? 1 Answer
Why WWW class is not working with WebGL 2 Answers
How can I get a string to work as the key to a dictionary filled with the text of a www object? 0 Answers
How can I access an external folder in the WebGL build of my app? 1 Answer