'Unity - create a common menu for multiple scenes
I've created a 3D game with 10 levels (10 scenes) with unity 2018. In the first scene I have added the canvas which displays the menu on click of ESC button.
But the problem is the menu is displayed only in the first level(scene). For the menu to display in other scenes I need to copy the same menu canvas to other scenes as well.
I am looking for a technique to have a common menu canvas for all the scenes without repeating it in all the scenes. Is there any way to do it?
Solution 1:[1]
Make it persist using DontDestroyOnLoad
void Awake()
{
DontDestroyOnLoad(gameObject);
}
Solution 2:[2]
You could use LoadScene.Additive, and have the Escape-Menu in a separate scene. The different scenes can then also be loaded and unloaded as necessary by some "master entity". I'm not sure if this is actually an antipattern, though.
Another option would simply be to make the menu a prefab and to (once) manually drag it into each scene.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vivek |
| Solution 2 | TeeGeeVee |
