public int highScore = 0; // highScore of level void Awake() { // Setting up the reference. playerControl = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>(); highScore = StatsService.GetHighScore(SceneManager.GetActiveScene().name); }
public Transform[] levelButtons; // Array of all the levelButton. void OnEnable() { LevelData levelData; List <LevelData> levelDataToUnlock; int highScore; //First, calcul the link between level for (int i = 0; i < levelButtons.Length; i++) { levelData = levelButtons[i].GetComponent <LevelData>(); if (levelData == null) { continue; } highScore = StatsService.GetHighScore(levelData.nameLevel); levelDataToUnlock = levelData.buttonLevelToUnlock.ToList().Select(x => x.GetComponent <LevelData>()).ToList(); if (levelDataToUnlock != null) { foreach (LevelData dt in levelDataToUnlock) { if (dt.scoreLock != 0) { dt.lockedBy = dt.levelTextObject.GetComponent <Text>().text == "" ? levelData.nameLevel : dt.levelTextObject.GetComponent <Text>().text; dt.lockedHighScoreBy = highScore; dt.locked = true; } else { dt.locked = false; } } } } //Second, verify condition to unlock level for (int i = 0; i < levelButtons.Length; i++) { levelData = levelButtons[i].GetComponent <LevelData>(); if (levelData == null) { continue; } highScore = StatsService.GetHighScore(levelData.nameLevel); if (levelData.scoreLock == 0) { levelData.locked = false; } else if (levelData.locked) { if (levelData.lockedHighScoreBy >= levelData.scoreLock) { levelData.locked = false; } } ChangeStateLock(levelData, levelButtons[i], highScore, levelData.lockedBy); } }