I am using javascript and I want to load a .txt file and read the strings, I do not want to drag the txt files onto a game object as many posts tell people to do as I will be passing the level number into a loading function.
My txt files are simple such as
011
010
110
and are stored in /Levels/
Can anyone provide some help please?
check out the documentation of the TextAsset class
Not the answer but thanks anyhow…
Use System.IO.Streamreader. There’s quite a few topics about loading text files with that if you do a search on “streamreader”.
–Eric
I have it working now thanks. Docs need more work really.
(fixed)
Hello, i having problems to use the text read by streamreader as a variable,
I have txt file with “teste” write in it, but im unable to use it in a IF stantment:
look:
function Start() {
sr = new StreamReader( “loader.txt”);
line = sr.ReadLine();
while (line != null) {
print(line);
line = sr.ReadLine();
if (line == “teste”){
Application.LoadLevel (1);
print(“load level”);
}
if (line != “teste”){
print(“call form”);
}
}
the software ignore that: line == “teste”
and execute as line != "teste, but as i say, it even print as teste.
i already try it with number and diferents words…
Any thoughts?
Fix:
i found a error on a code before it, that change the value of the variable.
hi snicholls, can you give me hint how to do that because i cannot load .txt file!
here my code…
var rolloverText = “”;
var rolloverColor = Color.red;
private var originalColor : Color;
private var textDisplay : GUIText;
var asset : TextAsset;
function Start() {
//render teeksture
originalColor = renderer.material.color;
// if (rolloverText == “”) { rolloverText = “test”; }
if (rolloverText == “”) { rolloverText = print(asset.text);}
textDisplay = GameObject.Find(“Rollover Text Display”).guiText;
}
function OnMouseEnter() {
Debug.Log(textDisplay.gameObject.name);
textDisplay.text = rolloverText;
}
function OnMouseExit() {
Debug.Log(textDisplay.gameObject.name);
textDisplay.text = “”;
}
I using GUIText to display txt file…but how I can show text in txt file when I rollover the object…
Thanks