IEnumerator LevelUpAnimationCoroutine(int startingLevel, int startingExp, int expGained)
    {
        float expRemaining    = expGained;
        float expCurrent      = startingExp;
        int   currentLevel    = startingLevel;
        float totalExpToLevel = StaticCalcs.experienceToLevel(startingLevel);
        float accPerFrame     = expGained / 300f;
        float diffPerFrame    = 0;
        float totalExpSoFar   = 0;

        SetEXPText(currentLevel, expCurrent, totalExpToLevel);
        yield return(new WaitForSeconds(1));

        while (expRemaining > 0)
        {
            diffPerFrame += accPerFrame;
            // Level Up Conditional
            if (expCurrent == totalExpToLevel)
            {
                diffPerFrame    = 0;
                currentLevel   += 1;
                totalExpToLevel = StaticCalcs.experienceToLevel(currentLevel);
                ps.Play();
                expCurrent = 0;
            }
            float expTillLevelUp = totalExpToLevel - expCurrent;
            float expThisFrame   = Mathf.Min(expTillLevelUp, diffPerFrame, expRemaining);
            totalExpSoFar += expThisFrame;
            expRemaining  -= expThisFrame;
            expCurrent    += expThisFrame;
            SetEXPText(currentLevel, expCurrent, totalExpToLevel);
            finalScore.text = "FINAL SCORE:\n" + Mathf.Floor(totalExpSoFar);
            yield return(new WaitForFixedUpdate());
        }
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        string playerName  = PlayerPrefs.GetString(PrefKeys.playerName);
        int    playerLevel = PlayerPrefs.GetInt(PrefKeys.playerLevel);
        int    bestScore   = PlayerPrefs.GetInt(PrefKeys.bestScore);
        int    playerExp   = PlayerPrefs.GetInt(PrefKeys.playerExp);

        userName.text     = playerName;
        levelText.text    = "Level: " + playerLevel.ToString();
        topScoreText.text = "Best: " + bestScore.ToString();
        expText.text      = "EXP: " + playerExp + "/" + StaticCalcs.experienceToLevel(playerLevel);
    }
    void UpdatePlayerExp(int expGained)
    {
        int playerLevel = PlayerPrefs.GetInt(PrefKeys.playerLevel);
        int totalPointsNeededToLevelUp = StaticCalcs.experienceToLevel(playerLevel);
        int currentExp = PlayerPrefs.GetInt(PrefKeys.playerExp);
        int expAfter   = expGained + currentExp;

        if (expAfter >= totalPointsNeededToLevelUp)
        {
            int expTowardsNextLevel = expAfter - totalPointsNeededToLevelUp;
            PlayerPrefs.SetInt(PrefKeys.playerLevel, playerLevel + 1);
            PlayerPrefs.SetInt(PrefKeys.playerExp, 0);
            UpdatePlayerExp(expTowardsNextLevel);
        }
        else
        {
            PlayerPrefs.SetInt(PrefKeys.playerExp, expAfter);
            PlayerPrefs.Save();
        }
    }
示例#4
0
    // Use this for initialization
    void Start()
    {
        MainMenuGameState gameState = MainMenuGameState.instance;

        GetComponent <Text>().text = gameState.GetExp() + playerExpBaseText + StaticCalcs.experienceToLevel(gameState.GetPlayerLevel());
    }