- Home /
The question is answered, right answer was accepted
Menu problem
Why the animation buttons do not work after I press the play button on the game scene and in the pause menu, press to go to the main menu. And after these actions, animations do not work in the main menu.
https://vimeo.com/325662896
Pas: 12345
Answer by Robertelis · Mar 21, 2019 at 02:59 PM
I am thinking it does not work anymore because it deletes itself after you change the scene. You might wanna try using a Singleton also seeing your GameObjects for both scenes would be helpful.
Singleton example I use in my game:
void Awake()
{
int gameStatusCount = FindObjectsOfType<ExampleMenu>().Length;
if (gameStatusCount > 1)
{
gameObject.SetActive(false);
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}
Put this in your menu GameObject and switch ExampleMenu with the name of the Object.
I would also like to mention that this not the most optimized way of doing this, but the key element you want to use is DontDestroyOnLoad(gameObject);