// this function is called when the current level is completed, it saves progress and changes level public void EnterWinState() { if (GetComponent <PlayerController>().enabled) // security, we make sure we only do this once { GetComponent <PlayerController>().enabled = false; // there is no need to keep controlling the vehicle once the level is done (and it's used as a security) GameObject.Find("GameUI").GetComponent <GameUI>().ActivateWinText(); // we activate a text to notify the player he's completed the level MainManager.CompletedLevel(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); // we ask the MainManager to save the progress StartCoroutine(EnableWin(3f)); // we wait for a few seconds before loading the next level } }