- Home /
How to make a map from .txt file
Hello evryone i would like to ask you, how do you read data from a .txt file.
i want it to read this txt file
R,R,R,R,
R,D,D,R,
R,D,D,R,
R,R,R,R,
now what i want, is to have it divide this R's and G's in seperate letters and cross check them with my if statements.
current code (im reallllly new to this)
import System.IO; var fileName = "Map.txt";
var x : int = 0; var y : int = 1; var n : int = 0;
var StoneWallPrefab : Transform; var DirtWallPrefab : Transform;
function Start () { var sr = new StreamReader(Application.dataPath + "/" + fileName); var fileContents = sr.ReadToEnd(); sr.Close();
var lines = fileContents.Split(","[0]);
for (line in lines)
{
if(line == "R")
{
var StoneWPrefab = Instantiate(StoneWallPrefab,transform.position+Vector3(x,-1.5,y),transform.rotation);
x+=1;
n+=1;
}
if(line == "D")
{
var DirtWPrefab = Instantiate(DirtWallPrefab,transform.position+Vector3(x,-1.5,y),transform.rotation);
x+=1;
n+=1;
}
} }
please help ;D
What's wrong with it? What does it output that isn't expected?
Your answer
Follow this Question
Related Questions
Modifying a text file outside unity. 1 Answer
How to add text to an external .txt file? 1 Answer
WWW request works in Editor but not in IOS? 1 Answer
Multiple files for animation - play issue 0 Answers
String.Split With Backslash 2 Answers