@@ -29,7 +29,9 @@ public class JCS_SceneManager : JCS_Manager<JCS_SceneManager>
2929 public Func < bool > onSwitchSceneIn = null ;
3030 public Func < bool > onSwitchSceneOut = null ;
3131
32- private bool mIsEnteringSwitchScene = false ;
32+ private bool mSwitchSceneEntering = false ;
33+
34+ private bool mIsEnteringNextScene = false ;
3335
3436 [ Separator ( "Check Variables (JCS_SceneManager)" ) ]
3537
@@ -144,6 +146,7 @@ private void Awake()
144146 {
145147 RegisterInstance ( this ) ;
146148
149+ // Load early for better execution order for scripts.
147150 HandleAdditive ( ) ;
148151
149152 switch ( mSwitchSceneType )
@@ -260,7 +263,7 @@ private void Start()
260263
261264 private void Update ( )
262265 {
263- if ( mIsEnteringSwitchScene )
266+ if ( mSwitchSceneEntering )
264267 DoEnterSwitchScene ( ) ;
265268 else
266269 DoExitSwitchScene ( ) ;
@@ -298,6 +301,7 @@ private void OnOverlaySceneLoaded(Scene scene, LoadSceneMode mode)
298301
299302 string sceneName = scene . name ;
300303
304+ // Prevent scene loaded twice.
301305 mLoadedOverlaySceneNames . Add ( sceneName ) ;
302306
303307 // Execute event.
@@ -381,7 +385,7 @@ public void LoadScene(string sceneName, LoadSceneMode mode,
381385 }
382386
383387 // Mark loading scene.
384- mIsEnteringSwitchScene = true ;
388+ mSwitchSceneEntering = true ;
385389
386390 switch ( mSwitchSceneType )
387391 {
@@ -678,9 +682,18 @@ private void DoExitSwitchScene()
678682 /// </summary>
679683 private void EnterNextScene ( )
680684 {
685+ if ( mIsEnteringNextScene )
686+ return ;
687+
688+ mIsEnteringNextScene = true ;
689+
690+ // Don't set it to low, or else it will still be
691+ // not fade out when trying to load the next scnee.
692+ const float delay = 0.1f ;
693+
681694 // Delay a bit of time to make sure it's completely
682695 // fade out.
683- Invoke ( nameof ( InvokeEnterNextScene ) , 0.01f ) ;
696+ Invoke ( nameof ( InvokeEnterNextScene ) , delay ) ;
684697 }
685698 private void InvokeEnterNextScene ( )
686699 {
0 commit comments