My logic is simple: after conditions are met, display an image (an Image
class instance) and restart the stopwatch. After a certain time, reload the scene. In a MonoBehaviour
script I wrote:
if(stopwatch.ElapsedMilliseconds > sceneReloadTime)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
sceneReloadTime
time was set to 3000
, which should be 3 seconds, but after displaying the image for 3 seconds, the image remains there and the scene did not seem to have been reloaded.
Out of confusion I put a breakpoint and used Visual Studio's debug tool, and confirmed that it has indeed entered the if
and seems to have gone through LoadScene
. I hit continue
in VS and was led to a seemingly reloaded scene, but very dark as if the exposure has been tuned down to near zero.
This "dark world", however, only appears when I use VS debug and hit continue. If I play in Unity it never seems to reload and will be stuck on the image forever.
What could have gone wrong? Thank you.
stopwatch.ElapsedMilliseconds
is scene-independent, so when the scene reloads it is still on the old value, which results in the scene getting reloaded in an infinite loop? \$\endgroup\$