- Home /
Question by
Lychmaster · Aug 02, 2015 at 06:25 PM ·
androidtextfile-iostreamreader
Reading from a file not working on Android
Hi, I have this block of code which loads from a plain text file the info needed to create a bunch of blocks in my breakout-like game. It works perfect on windows, but when I export my project and install it on my android phone, the level shows empty (blockCount shows 0), I am assuming that the file isn't loading, but I see no errors and all the other game logic appear to work correctly.
Any ideas what could I be doing wrong? I tryed to manually copy the file to what I tought was the datapath on my phone, but the result was the same.
sr = new StreamReader(Application.dataPath + "\\test.txt", Encoding.Default);
using (sr) {
do {
sLine = sr.ReadLine();
if (sLine != null) {
string[] sDatos = sLine.Split(',');
int iTipo = int.Parse(sDatos[0]);
Vector2 targetPosition = new Vector2 (float.Parse(sDatos[1]),float.Parse(sDatos[2]));
GameObject newBlock = (GameObject)Instantiate(blocks[iTipo], targetPosition, Quaternion.identity);
newBlock.GetComponent<Rocas>().setHP(int.Parse (sDatos[3]));
blockCount++;
Debug.Log("Tipo : " + sDatos[0] + "\n");
Debug.Log("X,Y : " + sDatos[1] + "," + sDatos[2] + "\n");
Debug.Log("HP : " + sDatos[3] + "\n");
}
}
while (sLine != null);
sr.Close();
}
Thanks in advance!
Comment