Hi friends,
The problem is that only one scene loads at one time and the other scene is not loaded so, I can’t access the other scene game object. How do we load more than one scene and access the gameobject in the other scene?
Regards,
vanhouten777.
You can load more than one scene at a time, if u want to access scene1 gameobject in scene2 then u have to use dontdestroyonload method.
Hi UnityCoder,
Can you show me the code or the link to the code. It would be helpful.
Regards,
vanhouten777.
Just open Unity help and search for DontDestroyOnLoad. There u can find a example script.
Hi UnityCoder,
How can we use one statement to prevent destroying the whole project hierarchy game objects? Or can we use dont destroy for the particular scene file?
Regards,
vanhouten777.
I show u the way that how to do that now you have to apply ur logic for that. If you have any problem then tell me i will do it with three four objects.
Hi Unity Coder,
How do we get the root of the scene?
Regards,
vanhouten777.
Hi UnityCoder,
Will Transform.root suffice?
Regards,
vanhouten777.
Hi UnityCoder,
will this do the trick
DontDestroyOnLoad (Transform.root);
Regards,
vanhouten777.
Just do one thing make one empty object put all your gameobjects except Camera into that empty object. Make one script and apply that script to empty object.
Write below code into that script.
void Awake() {
DontDestroyOnLoad(gameObject);
}