- Home /
How to save a file while connected to a server in the right dircetory
I want to save a file which stores the position of somethings in the scene. The problem is that it just works fine if i am using it in "Singleplayer" if i want to save a file during "Multiplayer" it doesn´t go into the right directory ,instead it goes into /Appdata/Username/ApplicationName .
this is the code:
import System; import System.IO; import System.Single; public class Saver extends MonoBehaviour { var fileName ="test.txt"; var fw : StreamWriter; var Blocks : GameObject[]; var ainput : String; var world : Transform; var maxsize : int ; function Save() { Blocks= new Array(gameObject.FindGameObjectsWithTag("1")); Debug.Log(Blocks); WriteFile(fileName); }
function Lade()
{
ReadFile(fileName);
/*for(var k=0;k < Blocks.length;k++)
{
Network.Instantiate(Blocks[k],Blocks[k].transform.position,Quaternion.identy,0);
}
*/
}
function WriteFile(fileName : String)
{
if (File.Exists(fileName))
{
Debug.Log(fileName+" already exists.");
return;
}
fw = File.CreateText(fileName);
for (var i =0;i < Blocks.length;i++)
{
fw.WriteLine(Blocks[i].GetComponent(Block).id.ToString);
fw.WriteLine(Blocks[i].transform.position.x);
fw.WriteLine(Blocks[i].transform.position.y);
fw.WriteLine(Blocks[i].transform.position.z);
}
//sw.Flush();
fw.Close();
}
function ReadFile(filepathWithName : String) {
sr = new File.OpenText(filepathWithName);
ainput = "";
var i=0;
while (true) {
ainput = sr.ReadLine();
if (ainput == null) {
break;
}
ainput = sr.ReadLine();
ainput = sr.ReadLine();
ainput = sr.ReadLine();
ainput = sr.ReadLine();
i++;
maxsize=i;
}
sr.Close();
Blocks=new Array(maxsize);
sr = new File.OpenText(filepathWithName);
i=0;
var x : float;
var y : float;
var z : float;
var chunk : int;
ainput = "";
var curid : int;
while (true) {
ainput = sr.ReadLine();
if (ainput == null) {
break;
}
curid=parseInt(ainput);
//Blocks[i].name=ainput;
ainput = sr.ReadLine();
x=parseFloat(ainput);
ainput = sr.ReadLine();
y=parseFloat(ainput);
ainput = sr.ReadLine();
z=parseFloat(ainput);
ainput = sr.ReadLine();
chunk = parseInt(ainput);
networkView.RPC("placeBlock",RPCMode.AllBuffered,curid,Vector3(x,y,z));
i++;
}
sr.Close();
}
}
Comment