The Project works fine, until a certain point is reached, then suddenly it starts throwing NRE's. Here's some source code :
void Start(){
myhealth = GetComponentInChildren<HealthBar>();
if(myhealth == null)
{
Debug.Log("myhealth is null !!"); //It never outputs something here
}
}
//And Here it works :
public void ApplyDamage(float amount)
{
myhealth.DamageEnemy(amount);
if (GetHealth() <= 0)
{
[...]
}
}
//Then suddenly it throws NRE's here when accesing it from another Script :
public void AddHealth(float a)
{
myhealth.HealEnemy(a); //Here
}
public float GetHealth()
{
return myhealth.GetHealth(); //And here
}
In the HealthBar script there are these variables and these functions:
public float maxHealth;
public float currentHealth;
private float originalScale;
public void DamageEnemy(float giveDamage)
{
currentHealth -= giveDamage;
}
public void HealEnemy(float heal)
{
currentHealth += heal;
}
public float GetHealth()
{
return currentHealth;
}
There doesn't seem to be a reason for the Script to be throwing NRE's, but it still does.
HealthBarscript