RiftMayhem/Assets/Scripts/UI/PlayerLevelTextController.cs

39 lines
1.2 KiB
C#

using Kryz.CharacterStats.Examples;
using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PlayerLevelTextController : MonoBehaviour
{
[SerializeField] private TMP_Text level;
[SerializeField] private TMP_Text experienceBar;
[SerializeField] private Image experienceBarFill;
PlayerCharacterStats player;
PhotonView photonView;
private void Awake()
{
photonView = GetComponentInParent<PhotonView>();
player = GetComponentInParent<PlayerCharacterStats>();
}
// Start is called before the first frame update
void Start()
{
player.level.OnLevelUpEvent.AddListener(UpdateLevelText);
player.level.OnExperienceChanged.AddListener(UpdateLevelText);
UpdateLevelText();
}
public void UpdateLevelText()
{
level.text = player.level.currentLevel.ToString();
experienceBar.text = $"{player.level.GetCurrentExperience().ToString("F1")}/{player.level.FinalExperienceThreshold.ToString("F1")}";
experienceBarFill.fillAmount = player.level.GetCurrentExperience() / player.level.FinalExperienceThreshold;
}
}