I Need Some Help With My Enemy Spawn Script

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);

        }

}

1 Answer

1

if you have placed this script onto the enemy gameObject then:

The curHealth is never going below or equal to zero so the Enemy GameObject is not being destroyed plus i dont know why you are adding zero to the curhealth every frame.

check if curhealth changes in the inspector