- Home /
Question by
SolidSlish · Apr 21, 2018 at 04:48 PM ·
scenelevelreset
How to Reset Scene after Level Completion
So, when I complete a level, the game is supposed to take me back to the main menu, which it does. However, after taking me back, the game also still remembers all the objects I collected during gameplay, making levels super easy. I want to make it so that the whole scene resets after the level is completed.
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour {
bool gameHasEnded = false;
public float restartDelay = 1f;
public GameObject completeLevelUI;
public void CompleteLevel()
{
completeLevelUI.SetActive(true);
}
public void EndGame()
{
if (gameHasEnded == false)
{
gameHasEnded = true;
Debug.Log("GAME OVER");
Invoke("Restart", restartDelay);
}
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
Comment
Your answer
Follow this Question
Related Questions
Resetting a Scene 2 Answers
Loading Scene on a series of events 2 Answers
Photon JoinRandomRoom customGameProperties? Load proper scene 0 Answers
How to restart a "prefab'd" level? ;) 0 Answers
Script Help Scene Complete Level 1 Answer