- Home /
Question by
SonicDirewolf · Nov 16, 2017 at 02:03 PM ·
gameobjectdestroydontdestroyonload
DontDestroyOnLoad for a specific scene
I have a scene called 'game'. And a gameobject. Every time the player selects the restart button, the game scene loads again. I don't want the gameobject to destroy when the game scene is loaded fresh. But when the player switches to the menu scene I want the gameobject to destroy. How can I do this? Thank you.
Comment
Best Answer
Answer by NickJVaccaro · Nov 16, 2017 at 03:05 PM
Even if you say DontDestroyOnLoad for the gameobject, you can still destroy it normally. So when the menu scene loads, check for existence of the gameobject and if it exists, Destroy it then. Then in the 'game' scene, check for existence of the gameobject, and if it doesn't exist, create a new one.
Your answer
