Continuation of slider approach

Duplicate your slides and tailor it to be an experience bar (which I will update in the “displaying the level” lecture, so this includes everything needed for when that happens, that way the slider will grow with how close we are to leveling).

The Text below will give total xp (which we can reset on level up or keep as lifetime total xp gained, your choice really)

new script ExperienceDisplay.cs

using System.Collections;
using UnityEngine;
using TMPro;

namespace RPG.Resources
{
    public class ExperienceDisplay : MonoBehaviour
    {
        [SerializeField] GameObject xpPercentSlider;
        [SerializeField] TextMeshProUGUI xpText;
        [SerializeField] TextMeshProUGUI levelText;
        Experience xpScript;

        private void Awake()
        {
            xpScript = GameObject.FindWithTag("Player").GetComponent<Experience>();
        }
        
        IEnumerator Start()
        {
            yield return new WaitForSeconds(0.1f);
            SetXpText();
            SetSliderPercentToNextLevel();
            SetLevelText();
        }

        private void Update()
        {
            SetXpText();
            SetSliderPercentToNextLevel();
        }


        private void SetXpText()
        {
            var xp = xpScript.GetXp();
            xpText.text = xp.ToString();
        }

        private void SetSliderPercentToNextLevel()
        {
            //throw new NotImplementedException();
        }

        private void SetLevelText()
        {
            //throw new NotImplementedException();
        }
    }
}
3 Likes

Awesome job!

Privacy & Terms