Ejemplo n.º 1
0
    void UnlockAbility(string name, int level)
    {
        int currentLevel;
        var availableCoins = PlayerPrefsManager.GetCoins();

        switch (name)
        {
        case "Double Jump":
            currentLevel = PlayerStatsManager.GetDoubleJumpLevel();
            if (level == currentLevel + 1 && availableCoins >= doubleJumpCost)
            {
                PlayerStatsManager.SetDoubleJumpLevel(level);
                PlayerPrefsManager.SetCoins(availableCoins - doubleJumpCost);
            }
            UpdateDoubleJump();
            break;

        case "Speed":
            currentLevel = PlayerStatsManager.GetSpeedLevel();
            if (level == currentLevel + 1 && level - 1 < speedCosts.Length && availableCoins >= speedCosts[level - 1])
            {
                PlayerStatsManager.SetSpeedLevel(level);
                PlayerPrefsManager.SetCoins(availableCoins - speedCosts[level - 1]);
            }
            UpdateSpeed();
            break;

        case "Jump Force":
            currentLevel = PlayerStatsManager.GetJumpForceLevel();
            if (level == currentLevel + 1 && level - 1 < jumpForceCosts.Length && availableCoins >= jumpForceCosts[level - 1])
            {
                PlayerStatsManager.SetJumpForceLevel(level);
                PlayerPrefsManager.SetCoins(availableCoins - jumpForceCosts[level - 1]);
            }
            UpdateJumpForce();
            break;

        default:
            Debug.LogError("Ability " + name + " not recognized");
            break;
        }
        UpdateCoins();
    }