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:
before moving to the next scene, i call to not destroy the Constants script:
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
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?
A simple way that is ok here is to use a static class.
Put this in a script, no need to give the script to any object. In your game, just call
A static class is made of static variables that are created before the game starts and are destroyed after the game is over (or crashes). You can then access your data anywhere and anytime in your game. It can be convenient to have a storage class for info that you want to keep all over the game like score, achievements and so on.
answered Oct 19 '12 at 02:25 PM