private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Home") && !DayNightManager.GetDay()) { hasWon = true; winTransition = WINTRANSITIONTIME; } }
// Update is called once per frame void Update() { if (hasWon) { Debug.Log(winTransition); winTransition -= Time.deltaTime; backgroundImage.color = new Color(1, 1, 1, 1 - winTransition / WINTRANSITIONTIME); if (winTransition < 0) { switch (SceneManager.GetActiveScene().name) { case "01_Level_TUTO": PlayerPrefs.SetFloat("Photo0", 1); SceneManager.LoadScene("MainMenu"); break; case "02_Level_Cliff": PlayerPrefs.SetFloat("Photo1", 1); SceneManager.LoadScene("MainMenu"); break; case "03_Level_Hole": PlayerPrefs.SetFloat("Photo2", 1); SceneManager.LoadScene("MainMenu"); break; case "04_Level_Final": PlayerPrefs.SetFloat("Photo3", 1); SceneManager.LoadScene("MainMenu"); break; default: SceneManager.LoadScene("MainMenu"); break; } } } // TODO : Remove if (Input.GetKeyDown("n")) { Debug.Log("Cheat code activated"); DayNightManager.SetDay(!DayNightManager.GetDay()); } if (Input.GetKeyDown("r")) { Debug.Log("Reloading level"); SceneManager.LoadScene(SceneManager.GetActiveScene().name); } GetComponentInChildren <InteractionCollider>().canInteract(DayNightManager.GetDay()); if (Input.GetButtonDown("Pickup") && !GetComponent <CharacterMovement>().IsJumping() && !storm.IsFalling()) { Queue <GameObject> items = new Queue <GameObject>(interactibles); if (items.Count > 0) { GameObject item = items.Dequeue(); if (item.CompareTag("Neon") && DayNightManager.GetDay()) { RemoveNeon(item); } if (item.CompareTag("Door") && DayNightManager.GetDay()) { item.GetComponentInParent <DoorManager>().Open(); interactibles.Remove(item); GameObject.Find("Frame").gameObject.SetActive(false); } if (item.CompareTag("Rift")) { Destroy(item); GameObject.FindGameObjectWithTag("Storm").GetComponent <PictureBehaviour>().StartAnimation(); } } } if (Input.GetButtonDown("PlaceObject") && !GetComponent <CharacterMovement>().IsJumping() && !storm.IsFalling() && DayNightManager.GetDay()) { if (currentNeonCount > 0) { PlaceNeon(); } } }
void Update() { if (!stormHasStarted && deathByFall) { fallingTimer -= Time.deltaTime; float newScale = fallingTimer / INITIALFALLINGTIMER; player.transform.localScale = new Vector3(newScale, newScale, newScale); if (fallingTimer < 0) { stormHasStarted = true; } } if (currentStormTimer > 0 && stormHasStarted) { if (!deathByFall) { currentStormTimer -= Time.deltaTime; } else { currentStormTimer -= Time.deltaTime * (initialStormTimer / 4); } if (currentStormTimer < initialStormTimer / 2) { stormImage.color = new Color(deathByFall ? 0 : 1, deathByFall ? 0 : 1, deathByFall ? 0 : 1, 1 - currentStormTimer / (initialStormTimer / 10)); } } else if (!runningOutOfTime && stormHasStarted) { runningOutOfTime = true; TriggerGameOver(); } if (runningOutOfTime && !gameOverIsDisplayed) { if (gameOverIsFadingIn) { currentGameOverApparitionTimer -= Time.deltaTime; Color gameOverTextColor = gameOverTextMesh.color; gameOverTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 1 - currentGameOverApparitionTimer / INITIALGAMEOVERAPPARITIONTIMER); if (currentGameOverApparitionTimer < 0) { gameOverIsDisplayed = true; } } else { currentGameOverWaitTimer -= Time.deltaTime; if (currentGameOverWaitTimer < 0) { gameOverIsFadingIn = true; } } } if (gameOverIsDisplayed && !gameOverRestartIsDisplayed) { if (gameOverRestartIsFadingIn) { currentGamerOverRestartApparitionTimer -= Time.deltaTime; Color gameOverTextColor = gameOverTextMesh.color; gameOverRestartTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 1 - currentGamerOverRestartApparitionTimer / INITIALGAMEOVERRESTARTAPPARITIONTIMER); if (currentGamerOverRestartApparitionTimer < 0) { gameOverRestartIsDisplayed = true; } } else { currentGamerOverRestartWaitTimer -= Time.deltaTime; if (currentGamerOverRestartWaitTimer < 0) { gameOverRestartIsFadingIn = true; } } } if (gameOverIsFadingIn && Input.GetButtonDown("Pickup")) { // TODO : Replace the scene loading with the correct behaviour to restart the night deathByFall = false; player.transform.localScale = new Vector3(1, 1, 1); player.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation; if (DayNightManager.GetDay()) { Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name); } else { player.transform.position = GetComponent <PictureBehaviour>().GetPlayerNightInitialPosition(); stormHasStarted = false; runningOutOfTime = false; currentStormTimer = initialStormTimer; gameOverIsFadingIn = false; gameOverIsDisplayed = false; gameOverRestartIsFadingIn = false; gameOverRestartIsDisplayed = false; stormImage.color = new Color(1f, 1f, 1f, 0f); Color gameOverTextColor = gameOverTextMesh.color; gameOverTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 0); gameOverRestartTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 0); DayNightManager.ChangeCycle(); StartStorm(); } } }