using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Assets.Scripts.CharacterScripts{ public class ExpBarController : MonoBehaviour { public Slider slider; // This moves the exp bar image public Gradient gradient; // Even though the exp bar is 1 color, I'm using the same method to fill the bar public Image expFill; // The fill of the exp bar public PlayerController player; // Reference to the player void Start(){ // Find the player and initialize player = GameObject.FindGameObjectWithTag("Player").GetComponent(); } public void ResetExp(int maxExp){ slider.maxValue = maxExp; slider.value = player.playerLevel == 1 ? 0 : player.currentExp; // Set the exp back to the beginning or current player exp expFill.color = gradient.Evaluate(1f); } public void SetExp(int exp){ slider.value = exp; // Set the slider value to the current exp expFill.color = gradient.Evaluate(slider.normalizedValue); } } }