Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Reading text file in webplayer

Discussion in 'Scripting' started by sagarsarma1, Jun 10, 2015.

  1. sagarsarma1

    sagarsarma1

    Joined:
    Dec 9, 2013
    Posts:
    4
    Why is the below code failing? I am trying to open a text file in the webplayer.

    string url = Application.dataPath + @"/Move.txt";
    WWW request = new WWW (url);
    while ( !request.isDone) {
    Debug.Log( "Loading...");
    }
    Debug.Log ("Data: " + request.data);

    Console Error:

    You are trying to load data from a www stream which had the following error when downloading.
    Could not resolve host: E; Host not found
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    [ code][ /code] tags when pasting in code into the forums please, helps with formatting/readability. There is a sticky about them in the scripting section.

    I'm a little confused as to where the file is. Application.dataPath would suggest it's within the app/resources folder, but you are trying to use the WWW functions which streams content from other servers/sites :confused:

    if you just want to load a text file from the Assets/Resources/ folder in your app you can just use:

    Code (csharp):
    1.  
    2. TextAsset myFile = (TextAsset)Resources.Load("TextDoc.txt");
    3.  

    http://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html
     
  3. sagarsarma1

    sagarsarma1

    Joined:
    Dec 9, 2013
    Posts:
    4
    I am using WWW request to load the file as it is a web build For testing in editor mode the file is in Asset directory in editor mode. I think I will have to keep the txt file in the same directory as .3d file in web hosting. Hope it clarifies your questions.