Not sure but I don’t think you can have the Following line.
EnemyHealthManager EnemyHealthManager;
You have the exact same spelling for the class AND the object.
Then when you call it later
if(EnemyHealthManager != null) <<<ADDITION<<<
{
if (timer >= timeBetweenAttacks && playerInRange && EnemyHealthManager.currentHealth > 0) <<<this is where the null reference exception was
}
It won’t work as you are referencing the class not the object. You can see this by the highlighted colouring.
In the if statement EnemyHealthManager is purple, showing it is referencing a class.
Rename the actual instance of the object something else (even just a different case)
• First you might want to rephrase your question above, it is confusing when you say “while the enemy does breath fire, it does give damage”.
• Second, in these situations always try to Debug/Print out what’s going on.
In this case, “attackDamage” might be set to zero. Or “Attack()” might not be getting called at all. To Make sure, replace your Attack() function with:
void Attack ()
{
Debug.Log("ATTACK WAS CALLED: " + gameObject.name);
timer = 0f;
if (playerHealth.currentHealth > 0) {
Debug.Log("ATTACK: Damage is : " + attackDamage.ToString() + " ON OBJECT: " + gameObject.name);
playerHealth.TakeDamage (attackDamage);
}
}
This may help you. If it still isn’t clear though, please post your output so we can help debug it.
• And third, your variable “EnemyHealthManager” should be “enemyHealthManager” (lowercase). Otherwise, you’re going to get errors all over the place. This might have been a copy/paste error, but I thought I would still point it out.