- Home /
Carry level slection menu through all levels
Hi
I have looked at some tutorials using dontdestroyonload, but none of them give a real answer to this.
I have a menu (dropdown) that loads contains all my levels (buttons) But now I want this menu to carry though to any level the user selects without duplicating itself, which seems to be the issue with dontdestroy as it will create a clone of itself, should the use go back to the same level again.
Thanks
Answer by Foulcloud · Aug 25, 2015 at 07:27 PM
I recommend creating a prefab to keep all your objects that should not be destroyed. Place your menu object in the prefab only and remove it from your levels. You will then need a script that runs on each level that checks for the existence of the prefab (using GameObject.Find("NameHere") == null). If none is found then the script should instantiate it. These types of prefabs should be placed in a folder called resources.
You can also temporarily put this prefab in a level to test and edit your menu. Once done you will want to remove it from the scene though.
Answer by puppeteer · Aug 26, 2015 at 08:22 AM
Why not assign the menu prefab to a variable in your gamecontroller (drag-drop prefab from project pane to variable slot in gamecontroller in your scene). When you press the menu button the level-menu gets instantiated.
That's all, no need for DontDestroyOnLoad();
Your answer
Follow this Question
Related Questions
How to get rid of the duplicates created by DontDestroyOnLoad? 3 Answers
Network Lobby Example from Asset Store doesn't work on SendReturnToLobby from Game Scene 0 Answers
Best way to deal with DontDestroyOnLoad when returning back to the same scene? 1 Answer
How do I stop the scene from switching when the gameObject is destroy / 0 Answers
Why do I loose my Animator? 0 Answers