- Home /
Question by
rodrigopereiramelo · Jul 06, 2020 at 09:27 PM ·
c#scene-loadingsingleton
Coroutine does not work when scenes changes
My coroutine stops to work when the scene changes and runs nothing after the yield. Even with Singleton Pattern, that keeps the code on the current screen, the coroutine does not complete. It should load the red scene, wait for one second and loads the blue scene. Any thoughts?
![alt text][1] [1]: /storage/temp/162882-code.png
code.png
(16.5 kB)
Comment
Answer by HappyPixel27 · Jul 06, 2020 at 10:10 PM
I would recommend to use DontDestroyOnLoad(this.gameObject) on the object where the coroutine is. Look at this documentation for more information on how to do it: https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html