- Home /
Question by
__JORDI123 · Jul 04, 2014 at 11:58 AM ·
javascript
UNITY3D: TEXTFILE I/O : Don't write same things
I have a function that stores the coordinates and the name of that chunk, but the problem is that this function gets called evrytime new chunks get generated, but the old ones keep being loaded if they are not far. So the result is that in the textfile, the function writes the chunks sometimes 2 times. I don't want this to happen and have the function only write every chunk once. Any help would be greatly appreciated. Thank you, Jordi
This is my code:
function saveLoadedChunk() {
var loadedChunks : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
var fileName = "C:/Reactor Games/chunks.txt";
var sw : System.IO.StreamWriter = new System.IO.StreamWriter(fileName, true);
for (var i = 0; i < loadedChunks.length ; i++) {
if(loadedChunks[i].name.Substring(0,5) == "Chunk" || loadedChunks[i].name.Substring(0,5) == "_TERR") {
if(loadedChunks[i].tag != "Player") {
var xco = loadedChunks[i].transform.position.x;
var yco = loadedChunks[i].transform.position.y;
var zco = loadedChunks[i].transform.position.z;
var stringToWrite = "Chunk (" + xco + ", " + yco + ", " + zco + ")";
sw.WriteLine(stringToWrite);
}
}
}
sw.Flush();
sw.Close();
}
Comment