Hi ive been looking for a tutorial on saving and havnt been able to find one, heres what i wanna do. when a function is called, i wanna have the scene make a file that saves some variables to it, then when the scene is loaded it checks if a certain files exsists if it does then it loads the variables into a certain script, how would i go about doing this?
with the IO class.
for example:
import System.IO;
function writeStuffToFile(){
var stuff : String = "stuff";
File.WriteAllText(Application.dataPath +"/stuff.txt",stuff);
}
function readLevelFromFile(){
var stuff : String;
stuff = File.ReadAllText(Application.dataPath +"/stuff.txt");
print(stuff);
}
EDIT: indeed. it should be print. thanks.
println(stuff);
I don’t think Unity supports println. You can use:
print (stuff)
or
Debug.Log (stuff)
instead.
I found the blog post at http://pennymo.com/2009/11/21/xml-and-unity-3d/ quite a nice read regarding reading and writing save files (and I found the tips useful). However, not really knowing the “inner workings” of anything, I can’t vouch for that being the best method in any way. Works for me, though.