leo
Junior vMember
Posts: 28
|
Post by leo on Apr 29, 2017 2:12:19 GMT
Hi, I want to stop DontDestroyOnLoad (gameObject) when I go back to my main menu.
What should I do?
|
|
leo
Junior vMember
Posts: 28
|
Post by leo on May 3, 2017 1:01:15 GMT
bump, anyone can help me?
|
|
|
Post by sickscore on May 3, 2017 7:10:32 GMT
bump, anyone can help me? Not sure if I understand you correct, but something like this should work. // since OnLevelWasLoaded is depricated, we use the new way using UnityEngine.SceneManagement;
void Awake () { DontDestroyOnLoad (this.gameobject) }
void OnEnable () { SceneManager.sceneLoaded += OnLevelFinishedLoading; }
void OnDisable () { SceneManager.sceneLoaded -= OnLevelFinishedLoading; }
void OnLevelFinishedLoading (Scene scene, LoadSceneMode mode) { if (scene.name == "MainMenu") // or better compare scene objects instead of their names Destroy(this.gameobject); // manual destroy the gameobject } Untested code written on my iPhone, don't blame formatting :D Geers, sickscore
|
|