Jelajahi Sumber

修复运行结束后依然会有怪物刷新

wgl 5 bulan lalu
induk
melakukan
9251894a61
1 mengubah file dengan 3 tambahan dan 0 penghapusan
  1. 3 0
      ActionTowerDefense/Assets/Scripts/EnemyCreater.cs

+ 3 - 0
ActionTowerDefense/Assets/Scripts/EnemyCreater.cs

@@ -144,6 +144,7 @@ public class EnemyCreater : MonoBehaviour
     void OnDestroy()
     {
         // 当 GameObject 销毁(如游戏停止)时取消任务
+        StopAllCoroutines();
         _cancellationTokenSource?.Cancel();
         _cancellationTokenSource?.Dispose();
     }
@@ -151,6 +152,8 @@ public class EnemyCreater : MonoBehaviour
     void OnDisable()
     {
         StopAllCoroutines();
+        _cancellationTokenSource?.Cancel();
+        _cancellationTokenSource?.Dispose();
     }
     public void OnGameTimeChange(float gameTime)
     {