I wrote a script for an enemy spawn, but the when the player attacks, the clones don’t die, even though the EnemyHealth script is activated on the clones of the enemy in the inspector. I am new to Unity and I wanted anyone help me out, C# (C Sharp) preferred.
Here is the script that I used.
NOTE: Disregard the “healthBarLength”. I forgot to take that part out.
using unityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
public int scoreValue = 10;
public float healthBarLength;
void Start
{
}
void Update ()
{
AddjustCurrentHealth (0);
}
public void AddjustCurrentHealth (int adj) {
curHealth += adj;
if (curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if (maxHealth < 1)
maxHealth = 1;
if (curHealth <= 0)
{
ScoreManager.score += scoreValue;
Destroy (gameObject);
}
}