Read Text File (webplayer game)

I’ve been reading many posts and trying to understand how to read a text file but have been unsuccessful.

The purpose is to create a word game and check weather that word exists in the text file. The text file looks like this:
abaft
abalone
abandon
abandoned
abandonedly
abandonment
abase
etc…

I’ve also been reading that I may have to use the WWW class if this is a webplayer game but Im not sure if thats true or not? I wont be writing to the text file just reading each line to see if a word exists in it, can I do this without WWW for a webplayergame?

So my main question is how do I check for words in the text file for a webplayer game?

I’ve tried to different way (unsuccessful).

  1. I get error Could not find file “C:\Users\Desktop\Dojo\Assets\5desk.txt” and I dont fully understand this way?
import System.IO;
var fileName = "5desk.txt";

function Start () {
    var sr = new StreamReader(Application.dataPath + "/" + fileName);
    var fileContents = sr.ReadToEnd();
    sr.Close();

    var lines = fileContents.Split("\n"[0]);
    for (line in lines) {
        print (line);
    }
}
  1. will only print (abaft abalone) so its probably not going through the whole text file
var asset : TextAsset;

function Start()
{
    print(asset.text);
}

If someone is feeling generous Id really appreciate some help on getting this set up to be able to check if a word exists in the text file. I’ll probably create a simple button to do the check.

Web players have no access to the local filesystem for security reasons. You need to use TextAsset, so the file is included in the build.

You need to click on the output in the console so you can see everything past the first two lines.

–Eric

Ahh… Eric5h5 you are the MAN!!!

var asset : TextAsset;
var whatWord : String;
var b : boolean;

function Start()
{
    //print(asset.text);
}
function OnGUI () 
{
    if (GUI.Button (Rect (20,40,80,20), "Level 1")) 
    {
        b = asset.text.Contains(whatWord);
        
        print(b);
       
    }
}