- Home /
Answer by Rabbit-Stew-dio · Feb 03, 2013 at 03:04 AM
When you load a new scene/level, Unity normally destroys all objects of the old scene before it creates the objects of the new scene.
You can mark objects from the previous scene to survive the mass-killing when a new scene is loaded by calling DontDestroyOnLoad(..).
Be careful: If the object you mark as survivor contains references to objects from the old scene, then these references will be invalid, as the objects have been destroyed. You also have to call destroy for that object yourself when you no longer need it, as Unity will NEVER destroy that object for you.
They are just ordinary GameObjects - so you access them like any other game object: by looking them up by name or tag.
Use either 'GameObject.FindWithTag' or use 'Object.FindObjectOfType' to get your gameobject/mono-behaviour.
Answer by cdrandin · Feb 03, 2013 at 02:18 AM
You will need to serialize the info and have to access it when ever you want. I don't think you can access variables from another scene as it doesn't really make sense as to how Unity gets its things to work.
See if this helps. http://blogs.unity3d.com/2012/10/25/unity-serialization/
Your answer
Follow this Question
Related Questions
Script Help Scene Complete Level 1 Answer
Creating and Accessing Unique Variables for Each Player on a Network 0 Answers
How to keep count of enemies left 2 Answers
Load Scene 1 Answer
Playing music while scenes change? 4 Answers