public void Win() { Debug.Log("YOU WIN THE LEVEL"); Player.Instance.gameObject.SetActive(false); PlayerGUI.Instance.Disable(); StartCoroutine(VictoryCoroutine()); IEnumerator VictoryCoroutine() { float t = 0.0f; LoadingUI.SetActive(true); while (t < 3) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(t / 3.0f); yield return(null); } BoidsManager.ClearBoids(); PlayerGUI.Instance.Disable(); SceneManager.LoadScene(1); yield return(null); } }
public void GameOver() { Debug.Log("You died"); Player.Instance.gameObject.SetActive(false); var volume = Camera.main.GetComponent <PostProcessVolume>(); volume.profile.TryGetSettings(out ChromaticAberration chromatic); chromatic.intensity.value = 0.0f; OnStartedLoad?.Invoke(); PersistentData.Instance.DecreaseLives(); if (PersistentData.Instance.Lives <= 0) { PersistentData.Instance.ResetLives(); PersistentData.Instance.ResetMultiplier(); PersistentData.Instance.Level = 0; StartCoroutine(GameOverRoutine()); return; } IEnumerator GameOverRoutine() { float t = 0.0f; LoadingUI.SetActive(true); PlayerGUI.Instance.Disable(); FadeImage.color = Color.black.withAlpha(0.0f); while (t < 3) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(t / 3.0f); yield return(null); } GameOverObject.SetActive(true); GameOverObject.GetComponentInChildren <TextMeshProUGUI>().text = $"GAME OVER\nYour Score Was\n{PersistentData.Instance.Score}"; if (PlayerPrefs.GetInt("Highscore", 0) == PersistentData.Instance.Score) { GameOverObject.GetComponentInChildren <TextMeshProUGUI>().text += "\nNEW HIGH SCORE!"; } PersistentData.Instance.ResetScore(); yield return(new WaitForSeconds(3f)); GameOverObject.SetActive(false); LoadingUI.SetActive(false); LoadLevel(); yield return(null); } StartCoroutine(DieRoutine()); IEnumerator DieRoutine() { LoadingUI.SetActive(true); PlayerGUI.Instance.Disable(); float t = 0.0f; while (t < 3) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(t / 3.0f); yield return(null); } FadeImage.color = Color.black.withAlpha(1.0f); Vector3 forward = (SplineNoise3D.SplineHole[1].pos - SplineNoise3D.SplineHole[0].pos).normalized; Player.Instance.transform.position = SplineNoise3D.SplineHole[0].pos + forward * 2f; Player.Instance.SetForward(forward); Player.Instance.gameObject.SetActive(true); Player.Instance.MovementMachine.TransitionTo <IdleState>(); BoidsManager.ClearBoids(); int count = 0; foreach (var s in SplineNoise3D.SplineHole) { if (count > 2) { BoidsManager.Spawn(s.pos, s.radius * 0.5f, _BoidsPerSegment, Player.Instance.transform); } count++; } t = 0.0f; PlayerGUI.Instance.Enable(); while (t < FadeOutTime) { t += Time.unscaledDeltaTime; FadeImage.color = Color.black.withAlpha(1f - t / FadeOutTime); yield return(null); } FadeImage.color = Color.black.withAlpha(0.0f); Player.Instance.MovementMachine.TransitionTo <FlyingState>(); LoadingUI.SetActive(false); } }