// when player wants to go to next level public void ContinueNextLevel() { CollectableManager.Instance.Score += currentScore; CheckpointResult result = new CheckpointResult(); result.medal = currentMedal; result.score = currentScore; result.level = SceneTransition.Instance.CurrentLevel; result.maxPossibleScore = numCollectables; CollectableManager.Instance.AddCheckpointResult(result); // something else? // destroy singleton instance = null; if (SceneTransition.Instance.IsLastLevel) { OnGameFinish(); } else { SceneTransition.Instance.GoToNextLevel(); Destroy(gameObject); } }
void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); // destroy object when player goes to next level }