- Home /
Duplicate Question. Asked hundreds of times, google first!
How to pass data through scenes?
Hello
i have 2 scenes, Settings scene and a Gameplay scene.
in setting scene there is a sound option(on/off)
so if sound=off no sound in gameplay and viceversa
here is the sound script, the name of the script is Soundonoff
public int soundset;
void OnMouseDown()
{
if (gameObject.name == "Off")
soundset=0;
else if (gameObject.name == "On")
soundset=1;
}
and my gameplay script (simple version)
public Soundonoff ss;
if (ss.soundset==0)
//sound is off
else if(ss.soundset==1)
//sound is on
but i keep getting the error
"Object reference not set to an instance of an objet"
is there anyway to pass data through scenes?
PS:i already know about static and playerprefs so are these the only ways to pass data through scenes?
You could have a static C# class (not derived from $$anonymous$$onoBehaviour) with static properties that are initialized by a component in one scene and then can be used by a component in another scene.
A simple google gives
http://blog.christianhenschel.com/2013/05/16/how-to-pass-data-between-scenes-static-variables/
http://forum.unity3d.com/threads/global-variables-or-passing-data-between-levels.62809/
http://answers.unity3d.com/questions/532656/what-is-the-best-way-to-pass-data-between-scenes.html
http://stackoverflow.com/questions/19890538/accessing-information-between-scenes-in-unity