Reputation: 1443
If I switch the platform to web player i get the error system.io.file' does not contain a definition for readAllTex
,this method doesn't work,but it works if I swtch the platform target to pc
string readPath(){
string filepath = "wsPath.txt";
string wspath=Environment.NewLine;
if (File.Exists(filepath))
wspath = File.ReadAllText(filepath);
return wspath;
}
Upvotes: 1
Views: 3640
Reputation: 1683
This is due to the sandboxing security of the webplayer, which has certain limitations imposed to prevent malicious code being executed by a unity application via the browser.
Unity's docs include a page explaining this:
http://docs.unity3d.com/Manual/SecuritySandbox.html
Which includes the following brief description of the limitations:
In short, you cannot access the filesystem directly using the System.IO namespace. This has been disabled intentionally by Unity.
The best practice is to use the PlayerPrefs, or to load/save data via a remote web service. There's a discussion on the topic here:
http://forum.unity3d.com/threads/read-write-text-files-from-unity-webplayer.19046/
Upvotes: 2