// MAIN GAMEPLAY LOOP void Update() { // Is a video ad being played if (adsController.IsVideoAdPlaying()) { videoAdChecker = true; pausePanel.SetActive(true); } else { if (videoAdChecker) { videoAdChecker = false; pausePanel.SetActive(false); } } // Has the game started isPaused = pm.GetIsPaused(); bool playerAlive = player.GetPlayerIsAlive(); if (!hasStarted) { if (Time.timeSinceLevelLoad >= tapPromptTime) { pm.ToggleTapToStart(true); } hasStarted = player.GetPlayerStarted(); if (hasStarted) { pm.ToggleTapToStart(false); musicManager.PlayMusic(); } } // Is the game ongoing, paused, or over if (playerAlive && !isPaused) // Game is ongoing, player is moving { // Camera follow player mainCam.transform.position = player.transform.position - camOffset; // If the player is within range to generate a new chunk if (player.transform.position.z + playerZDistanceToGenerateChunk >= currEndZ) { CalculateChunk(); pg.GenerateChunk(currStartZ, currEndZ, currStep, currFrequency, maxConsecutiveColor); } Blocker.UpdatePlayerPos(player.transform.position.z); UpdateDistance(); CheckCoinSound(); } else if (!playerAlive && !gameOverCompleted) // Player has died, round is over { playPanel.SetActive(false); CalculateCoins(); isHighScore = distance > PlayerData.GetHighScore() ? true : false; // checks if current run is new high score pm.EndGame(coins, isHighScore); SaveAtEndGame(); gameOverCompleted = true; AddToDistance(); musicManager.PauseMusic(); } }