- Home /
Question by
Goldiedog123 · Aug 09, 2017 at 02:58 AM ·
c#scenedontdestroyonload
Destroying Dontdestroyonload in code
Hello unity community your looking good!
Cough Cough enough of that,
Sooo here is the question:
I'm trying to destroy the dontdestroyonload after the match finishes... in my game but I have no clue how to have it destroyed.
Example of my code:
IEnumerator Finish()
{
yield return new WaitForSeconds(3.0f);
NetworkManager.singleton.StopClient();
NetworkManager.singleton.StopHost();
// DESTROY DONTDESTROYONLOAD;
SceneManager.LoadScene(0);
}
THANKS IN ADVANCE IF YOU RESPOND. This problem is causing my game a lot of errors etc.
Comment
Answer by FlaSh-G · Aug 11, 2017 at 08:52 PM
You can destroy a GameObject that has been flagged with DontDestroyOnLoad like any other:
Destroy(something);
The reference(s) to any object you want to destroy has to be obtained the same way as always.