Question by
ybosss777 · Jul 08, 2020 at 12:52 PM ·
programming
I made a Level System but i cant display my current level on my Ui
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System;
public class PlayerLevel : MonoBehaviour {
LevelWindow level;
public Text levelText;
[SerializeField] private LevelWindow levelWindow;
public event EventHandler OnExperienceChanged;
public event EventHandler OnLevelChanged;
public int currentLevel = 1;
public int currentXP = 1;
public int toLevelUp;
void Start()
{
}
void Update()
{
}
public void AddExperience(int experienceToAdd){
currentXP += experienceToAdd;
if(currentXP >= toLevelUp){
currentLevel++;
if(OnLevelChanged != null) OnLevelChanged(this, EventArgs.Empty);
}
if(OnExperienceChanged != null) OnExperienceChanged(this, EventArgs.Empty);
}
public int GetLevelNumber(){
return currentLevel;
}
public float GetExperinceNormalized(){ return (float)currentXP/toLevelUp; } void Awake() { PlayerLevel playerLevel = new PlayerLevel(); Debug.Log(playerLevel.GetLevelNumber()); AddExperience(200); }
}
Comment