脚本导致场景加载非常缓慢

所以我有这个脚本(粘贴整个事情在它的当前状态):

using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.Events; using ooparts.dungen; using UnityEngine.UI; public class RoomMapManager : MonoBehaviour { public Map mapPrefap; private Map mapInstance; public int MapSizeX; public int MapSizeZ; public int MaxRooms; public int MinRoomSize; public int MaxRoomSize; public Image coverPanel; public int TileSizeFactor = 1; public static int TileSize; private UnityAction mapGenerationListener; private void Awake() { // mapGenerationListener = new UnityAction(FadeCover); } private void OnEnable() { // EventManager.StartListening("GenerationComplete", mapGenerationListener); } private void OnDisable() { // EventManager.StopListening("GenerationComplete", mapGenerationListener); } void FadeCover() { Time.timeScale = 1; coverPanel.color = new Color(0, 0, 0, 0); coverPanel.raycastTarget = false; } void Start() { //TileSize = TileSizeFactor; //BeginGame(); } void Update() { if (Input.GetKeyDown(KeyCode.R)) { RestartGame(); } } private void BeginGame() { mapInstance = Instantiate(mapPrefap); mapInstance.RoomCount = MaxRooms; mapInstance.MapSize = new IntVector2(MapSizeX, MapSizeZ); mapInstance.RoomSize.Min = MinRoomSize; mapInstance.RoomSize.Max = MaxRoomSize; TileSize = TileSizeFactor; //coverPanel.color = new Color(0, 0, 0, 1); //coverPanel.raycastTarget = false; //Time.timeScale = 0; mapInstance.Generate(); } private void RestartGame() { EventManager.TriggerEvent("GameRestarted"); StopAllCoroutines(); for (int i = 0; i < mapInstance._rooms.Count; i++) { foreach (GameObject g in mapInstance._rooms[i].Monsters) { Destroy(g); } } Destroy(mapInstance.gameObject); //BeginGame(); SceneManager.LoadScene("Prototype2"); } } 

注意唤醒,启用和启动如何不做任何事情。 当这个脚本作为一个游戏对象的组件被攻击的时候,这个游戏对象的场景加载得非常缓慢。 我的意思是它需要30s到1分钟,甚至在编辑器中加载。 当我将这个项目构建到个人电脑和Android上时,这种行为是一样的。 当我从编辑开始的时候,没有任何延迟。 我不知道是什么原因造成的。