Ejemplo n.º 1
0
    void  Awake()
    {
        XP           = 0;
        ExperienceUI = FindObjectOfType(typeof(XPUI)) as XPUI;

        //Load player's level.
        if (SaveAndLoad == true)
        {
            XP    = PlayerPrefs.GetFloat("XP");
            Level = PlayerPrefs.GetInt("Level");
            if (Level == 0)
            {
                Level = 1;
            }
        }

        ExperienceUI.SetXPBarUI();
    }
Ejemplo n.º 2
0
    //Please use the fucntion when you want to add experience to the player.
    public void AddXP(int Amount)
    {
        XP += Amount;

        if (Level < MaxLevel)           //If the player didn't reach the max level yet.
        {
            if (XP >= Level * Level1XP) //If the player's experience is high or equal to the required experience points to level up.
            {
                //Level up!
                XP -= Level * Level1XP;
                Level++;

                //Play the level up sound.
                if (LevelUpSound)
                {
                    GetComponent <AudioSource>().PlayOneShot(LevelUpSound);
                }
            }
        }

        //If this is the final level:
        if (Level == MaxLevel)
        {
            //Keep resetting the player's experience points.
            XP = 0;
        }

        //Save player's level and xp:
        if (SaveAndLoad == true)
        {
            PlayerPrefs.SetFloat("XP", XP);
            PlayerPrefs.SetInt("Level", Level);
        }

        ExperienceUI.SetXPBarUI();
    }