private IEnumerator GameLoop(LevelFile _file) { while (isPlaying) { bool completedAllWaves = false; while (isPlaying && !IsWaveBeaten()) { timeLeft -= Time.deltaTime; timerImage.Rotate(new Vector3(0, 0, -180.0f * Time.deltaTime)); if (timeLeft <= 0.0f) { isPlaying = false; //Random Level if (_file == null) { PlayerPrefs.SetInt("InfiniteScore", wave); } } ColourCells(false, true); yield return(null); } ColourCells(true, false); if (isPlaying) { isPlaying = GenerateWave(); if (!isPlaying) { completedAllWaves = true; } } if (!isPlaying) { wireManager.EndMode(); if (completedAllWaves) { int score = gridManager.GetEmptyCells(); ScoreText.text = score + " EMPTY CELLS"; LevelCompleteText.gameObject.SetActive(true); if (_file != null) { int highScore = PlayerPrefs.GetInt(_file.Name + "Score", -1); if (score > highScore) { PlayerPrefs.SetInt(_file.Name + "Score", score); } //Set Max Levels PlayerPrefs.SetInt(_file.Name + "Complete", 1); } yield return(FadeInText(LevelCompleteText, ScoreText, 0.5f)); } else { timerText.color = unsolvedWireColour; timerText.text = "0"; yield return(FadeInText(TimeUpText, 0.5f)); } yield return(new WaitForSeconds(1.0f)); } else { timeLeft += GetWaveClearTime(); } } ColourCells(true, false); Debug.Log("GAME OVER"); }