I have heard so much about xml saving game objects when switching scenes, but i can not find any usefull tutorials how to do it with javascript, or is it possible at all. I would be gratefull if someone could just write part of code or leave me some link to see how to save simple game object with one sprite renderer, and one script attached.
Is it possible to somehow save game object as Prefab, and then instantiate it in new scene?
In a script attached to the game object, include
DontDestroyOnLoad(gameObject);
in the Start() or Awake() methods.
This way your object will persist if you load a different scene and it will contain all variables and changes made to it previously.
This might help you:
http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading
//first attach this script to the game object and make your game object a prefab so you can add it to the other scenes and don’t delete it from the scenes
public class Data : MonoBehaviour
{
public static Data dat; //this will make the class static so you can enter it without get component .
void Awake ()
{
if (dat == null)
{
DontDestroyOnLoad(gameObject);// will save the game object when change the level.
dat = this;
}
else if (dat != this)//will keep one saved object so no conflict .
{
Destroy(gameObject);
}
}
}