Hi EDC, its showing the wrong value it should be showing 50 but it is showing the max of 250.
Health.cs
using System;
using System.Runtime.InteropServices.WindowsRuntime;
using UnityEngine;
using RPG.Saving;
using RPG.Stats;
using RPG.Core;
namespace RPG.Attributes
{
public class Health : MonoBehaviour, ISaveable
{
[SerializeField] float regenerationPercentage = 70;
float healthPoints = -1f;
bool isDead = false;
private void Start()
{
GetComponent<BaseStats>().onLevelUp += RegenerateHealth;
if (healthPoints < 0)
{
healthPoints = GetComponent<BaseStats>().GetStat(Stat.Health);
}
}
public bool IsDead()
{
return isDead;
}
public void TakeDamage(GameObject instigator, float damage)
{
print(gameObject.name + " took damage: " + damage);
healthPoints = MathF.Max(healthPoints - damage, 0);
if (healthPoints == 0)
{
Die();
AwardExperience(instigator);
}
}
public float GetHealthPoints()
{
return healthPoints;
}
public float GetMaxHealthPoints()
{
return GetComponent<BaseStats>().GetStat(Stat.Health);
}
public float GetPercentage()
{
return 100 * (healthPoints / GetComponent<BaseStats>().GetStat(Stat.Health));
}
private void Die()
{
if (isDead) return;
isDead = true;
GetComponent<Animator>().SetTrigger("die");
GetComponent<ActionScheduler>().CancelCurrentAciton();
}
private void AwardExperience(GameObject instigator)
{
Experience experience = instigator.GetComponent<Experience>();
if (experience == null) return;
experience.GainExperience(GetComponent<BaseStats>().GetStat(Stat.ExperienceReward));
}
private void RegenerateHealth()
{
float regenhealthPoints = GetComponent<BaseStats>().GetStat(Stat.Health)
* (regenerationPercentage /100);
healthPoints = MathF.Max(healthPoints, regenhealthPoints);
}
public object CaptureState()
{
return healthPoints;
}
public void RestoreState(object state)
{
healthPoints = (float)state;
if (healthPoints == 0)
{
Die();
}
}
}
}