After implementing the Lazy Value stuff, I just can’t seem to fix my leveling system. It was working before and now the character gets experience but doesn’t level up.
Now I get the following error:
NullReferenceException: Object reference not set to an instance of an object
RPG.Attributes.Experience.GainExperience (System.Single experience) (at Assets/OurScripts/Level and Stats/Experience.cs:21)
RPG.Attributes.Health.AwardExperience (UnityEngine.GameObject instigator) (at Assets/OurScripts/Attributes/Health.cs:86)
RPG.Attributes.Health.TakeDamage (UnityEngine.GameObject instigator, System.Single damage) (at Assets/OurScripts/Attributes/Health.cs:49)
RPG.Combat.Projectile.OnTriggerEnter (UnityEngine.Collider other) (at Assets/OurScripts/Combat/Projectile.cs:62)
The section it most directly points to seems fine when I check it:
[SerializeField] float experiencePoints = 0;
Health playerHealth;
public event Action onExperienceGained;
private void Awake()
{
playerHealth = GameObject.FindWithTag("Player").GetComponent<Health>();
}
public void GainExperience(float experience)
{
experiencePoints += experience;
onExperienceGained();
playerHealth.GetCurrentMaxHealth();
}
I could use some help fixing this issue. I’m pretty new to coding so I don’t really know how to go through every potential issue on my own.