I use C# script read a txt file,Display the txt word is good in the editer tool,but in the web can’t Display! why?
Security reasons. You don’t want some random web site having read/write access to your hard drive.
–Eric
You can read text files but they must be on the WWW, you can not access the local file system.
Yup, the above posts are spot on. The Unity Web Player is restricted from accessing local files for security reasons and so if you need to do this then have your file posted at a web address and use the WWW class. While testing in authoring you can write code that checks the current playback environment and if you’re in authoring read the local text file, if you’re in the web player then pull it from a URL using the WWW class. Alternatively, if the file won’t change much have both the in-editor and in-web player cases use the WWW class to pull the remote copy.
Thanks HiggyB!
@HiggyB Can you explain how to test the environment?
I found some threads mentioning a element “navigator” (for example http://forum.unity3d.com/viewtopic.php?p=74704)
But I couldn’t find any doc how to test if we are in a webplayer, iphone or standalone (pc/mac) unity player.
Remember, you’d be doing this testing inside the editor itself so I’m not sure that other thread has anything to do with this topic. For starters you can check if you’re inside of Unity itself via the Application class and its isEditor property:
If you need more than just a “in editor or not” check, like “in editor? in web player? on iPhone? etc.” then you’ll need to use the Application class once again, but this time its platform property:
Thanks! I don’t know why I didn’t see this Application class ![]()