Hi
I have been going through some posts about saving the content of a scene onto a file so that I can load it again at a later point. The posts I found was rather old though and seeing that there is a new version of Unity I thought maybe there are some new techniques? From what I have read so far I guess the following is a good approach;
Let’s say I have BrickA and BrickB in my project, and that’s about it.
-
Create a script that find all objects within a scene, then store them in an XML file; name/id of object (is it BrickA or BrickB?), position of object, any other usefull info that is specific to the Brick in question.
-
A script that reads the XML file and instantiates the objects based on the XML content, as well as set any custom variable as defined by the Brick type.
Does that sound like the right way to approach it? This is not supposed to be used for saving something mid-game, but rather a save/load feature for a level construction kit that will work when the game is actually running.
Moreover, if I use .NET XML loading methods, won’t that mean I can’t port the game to Mac, iOS and so on? How would I go about reading/writing XML while still being able to port? Also, XML is not a must (the format is bloated anyway), have anyone tried writing a custom file?
I must admit that I am on very thin ice here, so link to a really easy tutorial would be fantastic 
Sorry, I don’t have a proper tutorial for you. But the easiest way to save the positions would be to use PlayerPrefs. Unfortunately, the file in which PlayerPrefs is stored is quite hard to find, and you’d also be carrying with it, if you were to put the file on another computer, the player’s resolution settings, graphics settings, and full screen settings.
You could have the player copy and paste some code into a file of their choice, and then share it later.
Or, you could save the variable that has the position stored by using LoadLevelAdditive to bring it to the next scene.
But basically, you’d use some type of code like this:
var brick1 : Transform;
var brick2 : Transform;
var codeToCopy : String;
function SaveTheGame ()
{
var gos : GameObject[] = FindObjectsOfType(GameObject);
for (i=0; i<gos.length; i++)
{
//here is where your chosen method will be called if you choose to use variables
//if not, just return
return;
}
//PlayerPrefs method:
PlayerPrefsX.SetVector3("Position1", brick1.position);
PlayerPrefsX.SetVector3("Position2", brick2.position);
//etc...
//and for the copy and paste, use a variable such as
var position1 = brick1.position;
var position2 = brick2.position;
codeToCopy = ""+position1+" "+position2;
//and you'd have this code copyable by the player using a GUI text box
}
It varies depending on if you also want to save the rotation, etc. But Good Luck!
Also, for the code above, using the variables method would mean that you have to do something like “the variable = gos*.position;”*