IEnumerator RestartEverything() { SceneManager.LoadScene("Floor 1"); yield return(new WaitForFixedUpdate()); player = Player_S.self.gameObject; AudioManager = AudioManager_S.self; canvas = Canvas_S.self; canvasAsset = Canvas_S.self.GetComponent <Canvas>(); judgingSystem = JudgingSystem_S.self; secondCamera = SecondCamera_S.self.GetComponent <Camera>(); secondCamera.enabled = false; mainCamera = Camera_S.self.GetComponent <Camera>(); level = 1; canvas.getLevelUIText().text = "level " + level; QnA_S[] array = Resources.LoadAll <QnA_S>("Questions"); // takes all the QnA_S files from Resources for (int i = 0; i < array.Length; i++) { qnaArray.Add(array[i]); } BuildLevel(); }
// ** Coroutines ** IEnumerator FloorTransition() { GameObject door = GameObject.Find("Door"); GameObject elevator = GameObject.Find("Elevator"); door.GetComponent <Animator>().SetTrigger("Activate"); elevator.GetComponent <Animator>().SetTrigger("Activate"); secondCamera.GetComponent <Animator>().SetTrigger("Activate"); yield return(new WaitForSecondsRealtime(2f)); // Creates the background of the elevator GameObject elevatorBG = Instantiate(elevatorBackground, transform); yield return(new WaitForSecondsRealtime(2f)); // Reloads the Scene SceneManager.LoadScene("Floor 1"); yield return(new WaitForFixedUpdate()); // Loads Items important to the scene transition BuildLevel(); GameObject rail = Instantiate(elevatorRail, new Vector2(0, -4), Quaternion.identity); GameObject.Find("Tilemap_Building").GetComponent <TilemapRenderer>().enabled = false; for (int i = 0; i < UnityEngine.Random.Range(1 + level / 8, 4 + level / 4); i++) { Instantiate(alien, new Vector2(UnityEngine.Random.Range(-3f, 3f), UnityEngine.Random.Range(-1f, 2f)), Quaternion.identity); } yield return(new WaitForFixedUpdate()); // Finish animations related to the end of a scene transition door = GameObject.Find("Door"); door.GetComponent <Animator>().SetTrigger("NotOpen"); secondCamera.GetComponent <Animator>().SetTrigger("Activate"); elevator.GetComponent <Animator>().SetTrigger("Activate"); elevatorBG.GetComponent <Animator>().SetTrigger("Activate"); elevatorBG.GetComponentInChildren <Animator>().SetTrigger("Activate"); yield return(new WaitForSecondsRealtime(4f)); // Scene transition ends; runs code important to the new scene Destroy(elevatorBG); Destroy(rail); door.GetComponent <Animator>().SetTrigger("Activate"); canvas.showUnnecessaryUI(); Text levelUIText = canvas.getLevelUIText(); levelUIText.text = "Level " + level; // Updates the level text yield return(new WaitForSecondsRealtime(0.5f)); // Player can walk around GameObject.Find("Tilemap_Building").GetComponent <TilemapRenderer>().enabled = true; player.SetActive(true); Enemy_S.target = player.transform; Enemy_S.foundTarget = true; GameObject.Find("Hand").GetComponent <Pistol_S>().Reload(true); secondCamera.enabled = false; mainCamera.enabled = true; }