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).
- 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);
}
}
- 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.