Hi,
I have a script which reads the contents of a text file and then outputs to the GUI. It works fine in the editor, in scene and game view, but when I build and run (either the web player or a Mac standalone) I'm not seeing the text. Am I overlooking anything?
This is the script. The file is just a plain text file and sits in the Resources folder in my Assets folder.
import System.IO;
var fileName = "ratfacts.txt";
var letterPause = 0.2;
var linePause = 10;
var sound : AudioClip;
private var word;
function Start () {
var sr = new StreamReader(Application.dataPath + "/Resources/" + fileName);
var fileContents = sr.ReadToEnd();
sr.Close();
var lines = fileContents.Split("
"[0]);
for (line in lines) {
word = line;
// guiText.text += line + "
";
TypeText();
if(word.length > 1){
yield WaitForSeconds(linePause);
}else{
yield WaitForSeconds(2);
}
}
}
function TypeText () {
for (var letter in word.ToCharArray()) {
guiText.text += letter;
if (sound)
audio.PlayOneShot (sound);
yield WaitForSeconds (letterPause);
}
guiText.text += "
";
}
FTR here's the trivial way to use a text file in Unity http://answers.unity3d.com/answers/40481/view.html
– Fattie