So far I have managed to make the enemy explode using a prefab however the enemy seems to explode constantly when I start the game rather than after dying.
This is the enemy script:
void Awake ()
{
currentHealth = startingHealth;
}
public void TakeDamage (int amount)
{
currentHealth -= amount;
healthSlider.value = currentHealth;
if(currentHealth <= 0)
{
Destroy (gameObject);
}
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Background")
{
return;
}
Instantiate (explosion, transform.position, transform.rotation);
}