public void LoadCheckpoint() { CharacterData characterData = LoadCharacter(); // Get checkpoint info CheckPoint checkpoint = characterData.checkpoint; // have checkpoint if (checkpoint.stage != null) { float time = checkpoint.time; // Set character data // time TimeGUI timeGUI = GameObject.FindObjectOfType(typeof(TimeGUI)) as TimeGUI; timeGUI.SetTime(time); // key, jewellery List <ItemColor> keys = checkpoint.keys; Dictionary <ItemColor, int> jewellarys = checkpoint.jewellarys; Bag bag = GameObject.FindGameObjectWithTag("Player").GetComponent <Bag>(); bag.AddList(keys); bag.AddList(jewellarys); // checkpoint and position Transform player = GameObject.FindGameObjectWithTag("Player").transform; int checkpointId = checkpoint.checkPointId; Vector2 startPosition = Checkpoints.GetChild(checkpointId).position; for (int index = 0; index <= checkpointId; index++) // remove previous checkpoint first { // Destroy(Checkpoints.GetChild(index).gameObject); Checkpoints.GetChild(index).gameObject.gameObject.SetActive(false); } // Also remove collected item Key[] sceneKeys = GameObject.FindObjectsOfType(typeof(Key)) as Key[]; foreach (Key sceneKey in sceneKeys) // Loop by scene key { // destroy scene key gameObject if collected before if (keys.Contains(sceneKey.ItemColor)) { Destroy(sceneKey.gameObject); } } Jewellary[] sceneJewellarys = GameObject.FindObjectsOfType(typeof(Jewellary)) as Jewellary[]; Goal[] goals = GameObject.FindObjectsOfType(typeof(Goal)) as Goal[]; foreach (Jewellary sceneJewellary in sceneJewellarys) // Loop by scene key { // destroy scene key gameObject if collected before // And disable the red door ItemColor color = sceneJewellary.ItemColor; if (jewellarys.ContainsKey(sceneJewellary.ItemColor)) { Destroy(sceneJewellary.gameObject); if (color == ItemColor.red) // Red door can't open again { foreach (Goal goal in goals) { if (goal.redKey) { goal.DisableDoor(false); break; // break search red door } } } } } // Load player to checkpoint position player.position = startPosition; // Transition for player ready // StartCoroutine(LoadCheckpointTransition()); } }