private void UpdateCoinsStatsForLevel(int level)
    {
        int neededCoins = GamePrefController.LoadLevelRequrement(level + 1);

        neededCoinsText.text    = neededCoins.ToString();
        playButton.interactable = neededCoins <= totalCoins;
    }
 public void ResetProgress()
 {
     GamePrefController.ClearCoinsForLevels(levels.options.Count);
     UpdateCollectedCoinsIcons(levels.value);
     totalCoins          = GamePrefController.GetTotalCoinsForLevels(levels.options.Count);
     totalCoinsText.text = totalCoins.ToString();
 }
    private void UpdateCollectedCoinsIcons(int level)
    {
        int coins = GamePrefController.LoadCoinsForLevel(level + 1);

        coin1.color = coins > 0 ? Color.yellow : Color.grey;
        coin2.color = coins > 1 ? Color.yellow : Color.grey;
        coin3.color = coins > 2 ? Color.yellow : Color.grey;
    }
    public void LoadNextLevel()
    {
        int totalCoins     = GamePrefController.GetTotalCoinsForLevels(SceneManager.sceneCountInBuildSettings);
        int nextSceneIndex = SceneManager.GetActiveScene().buildIndex;

        do
        {
            nextSceneIndex++;
        } while (GamePrefController.LoadLevelRequrement(nextSceneIndex) > totalCoins && nextSceneIndex < SceneManager.sceneCountInBuildSettings);
        if (nextSceneIndex >= SceneManager.sceneCountInBuildSettings)
        {
            LoadMainMenuScene();
        }
        else
        {
            SceneManager.LoadScene(nextSceneIndex);
        }
        Time.timeScale = 1;
    }
    void Start()
    {
        levels.ClearOptions();
        scenes = new List <string>();

#if UNITY_EDITOR
        foreach (UnityEditor.EditorBuildSettingsScene scene in UnityEditor.EditorBuildSettings.scenes)
        {
            if (scene.enabled && scene.path != SceneManager.GetActiveScene().path)
            {
                scenes.Add(System.IO.Path.GetFileNameWithoutExtension(scene.path));
            }
        }
#endif

#if !UNITY_EDITOR
        scenes.Add("Level 1");
        scenes.Add("Level 2");
        scenes.Add("Level 3");
        scenes.Add("Level 4");
        scenes.Add("Jetpack level 1");
        scenes.Add("Jetpack level 2");
        scenes.Add("Bonus level");
        scenes.Add("Jetpack bounus level");
        scenes.Add("Secret level");
#endif

        levels.AddOptions(scenes);
        levels.value = 0;
        UpdateCollectedCoinsIcons(levels.value);
        UpdateCoinsStatsForLevel(levels.value);
        totalCoins          = GamePrefController.GetTotalCoinsForLevels(levels.options.Count);
        totalCoinsText.text = totalCoins.ToString();

        if (levelsRequrement != null)
        {
            for (int i = 0; i < levelsRequrement.Length; i++)
            {
                GamePrefController.SaveLevelRequrement(i + 1, levelsRequrement[i]);
            }
        }
    }
    public void ShowLevelFinishedPanel()
    {
        Time.timeScale = 0;
        bestCoins      = GamePrefController.LoadCoinsForLevel(SceneManager.GetActiveScene().buildIndex);
        currentCoins   = gameManager.Coins;

        currentCoin1.color = currentCoins > 0 ? Color.yellow : Color.grey;
        currentCoin2.color = currentCoins > 1 ? Color.yellow : Color.grey;
        currentCoin3.color = currentCoins > 2 ? Color.yellow : Color.grey;

        bestCoin1.color = bestCoins > 0 ? Color.yellow : Color.grey;
        bestCoin2.color = bestCoins > 1 ? Color.yellow : Color.grey;
        bestCoin3.color = bestCoins > 2 ? Color.yellow : Color.grey;

        if (currentCoins > bestCoins)
        {
            GamePrefController.SaveCoinsForLevel(SceneManager.GetActiveScene().buildIndex, currentCoins);
        }

        gameEndLevelPanel.SetActive(true);
    }