protected void Win(float winTime) { timer.Stopped = true; int starCount = stars.Length; for (int index = 0; index < stars.Length - 1; ++index) { if (winTime < times[index]) { break; } else { --starCount; } } int currentLevel = (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex - 1); if (starCount > int.Parse(PlayerPrefs.GetString(PlayerPrefKeys.STAR_RATING + currentLevel))) { PlayerPrefs.SetString(PlayerPrefKeys.STAR_RATING + currentLevel, starCount.ToString()); ///Not the best storage but it will have to do for today } if (!PlayerPrefs.HasKey(PlayerPrefKeys.STAR_RATING + (currentLevel + 1))) { PlayerPrefs.SetString(PlayerPrefKeys.STAR_RATING + (currentLevel + 1), "0"); //Unlock next } FindObjectOfType <PupulateLevels>().WonLevel(currentLevel, starCount); Ghost ghost = FindObjectOfType <Ghost>(); if (ghost != null) { if (ghost.BestTime > Time.time - startTime) { GhostSerializer.SerializeObject(snaps.ToArray(), Application.persistentDataPath + "/Level" + currentLevel + ".xml"); } } else { GhostSerializer.SerializeObject(snaps.ToArray(), Application.persistentDataPath + "/Level" + currentLevel + ".xml"); } congrats.gameObject.SetActive(true); }
void OnTriggerEnter2D(Collider2D other) { try { if (!saving) { saving = true; Data dataObject = GameController.dataStorage; int scoredMoney = GameController.score - GameController.startScore; EndGameController.scoredMoney = scoredMoney; dataObject.setMoney(GameController.score + ((int)Math.Floor((double)(scoredMoney / 100 * Globals.challenge_money_Percentage))) + Globals.challenge_Money); dataObject.setFinishedGames(dataObject.getFinishedGames() + 1); float highscore = dataObject.getHighscores()[GameController.gameType - 1]; float score = GameController.gameTimer; EndGameController.currentTime = score; EndGameController.highscore = highscore; EndGameController.finished = true; EndGameController.completed = true; if (highscore > score || highscore == 0) { List <float> scores = dataObject.getHighscores(); scores[GameController.gameType - 1] = score; dataObject.setHighscores(scores); Ghost ghost = new Ghost(PlayerController.ghostListX, PlayerController.ghostListY, PlayerController.ghostListFlip, PlayerController.ghostListSpeed, dataObject.getSelectedSkin()); GhostSerializer.Serialize(ghost, "Challenge" + GameController.gameType); } DataSerializer.Serialize(dataObject); GameController.dataStorage = dataObject; GameController.score = 0; GameController.amountOfPlatforms = 0; saving = false; } } catch (Exception e) { Debug.Log(e.Message); } finally { saving = false; SceneManager.LoadScene("Result"); } }
// Use this for initialization void Start() { points = GhostSerializer.DeSerializeObject(Application.persistentDataPath + "/Level" + (UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex - 1) + ".xml"); currentMaxIndex = 0; startTime = Time.time; }