- Home /
DontDestroyOnLoad cancelling when Main Menu is open
I want to stop DontDestroyOnLoad (gameObject); when I go back to my main menu so that my player doesn't load on the main menu. I tried
if (Application.loadedLevelName == "MainMenu") {
} else {
DontDestroyOnLoad (gameObject);
}
But I then looked at it and realized that it would only work if I went back to the Main Menu on the Main Menu.
Answer by meat5000 · Apr 27, 2014 at 12:48 AM
Destroy it manually.
Destroy()
I tried this on the button that brings me back to the main menu
Destroy(playerScript.gameObject);
Application.LoadLevel ("$$anonymous$$ain$$anonymous$$enu");
but it crashes the game every time I try.
That's actually what I originally had it as and then I swapped it to see if it would work.
Edit: Weird, it seems to work now. Thank you!!!
Your answer
Follow this Question
Related Questions
GetComponent doesn't work 2 Answers
Not loading correct Scene/Level 1 Answer
Changing something in another scene by answering correctly with GlobalManager 0 Answers
Multiple Instances of My Current Scene? 0 Answers
Scene changing 1 Answer