I have 2 scenes and wish to pass info from one to another. I have created in the first scene a script Constants on an empty game object that retains the data that I wish to save for the next scene.
Here it is:
public class Constants : MonoBehaviour {
public string scratchImageFront;
public string scratchImageBack;
void setScratchFront(string _scratchFront)
{
scratchImageFront = _scratchFront;
}
void setScratchBack(string _scratchBack)
{
scratchImageBack = _scratchBack;
}
}
Before moving to the next scene, I call to not destroy the Constants script:
GameObject constants = GameObject.Find("Constants");
Constants script;
script = constants.transform.GetComponentInChildren<Constants>();
DontDestroyOnLoad(constants);
Application.LoadLevel("scratch");
I then collect the data in my second scene and all is good. after I'm done in my second scene, I go back to my first scene
Application.LoadLevel("start");
and redo the same steps as I first did, the Constants script doesn't retain the new strings passed to it, it retains the old ones. Why?
I need to destroy the Constants script in my second scene so that everything works as it should, but i don't want this. What am I doing wrong?
LoadLevel("start")
; will create an instance again. – Kay