- Home /
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);
}
}
Answer by abhi_360 · May 20, 2015 at 10:42 AM
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613200033im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
FindObjectOfType with Variable 1 Answer
one scene multiple spawn points 1 Answer
Spawn player to a different scene 0 Answers
Multiple Spawn Points for fps character 1 Answer
3 spawn positions but one is ignored and i dont know why 2 Answers