using UnityEngine;
using System.Collections;
public class death : MonoBehaviour {
Transform curTransform;
void Start(){
curTransform = gameObject.GetComponent<Transform>();
curTransform = gameObject.transform;
}
void Update(){
EnemyHealth eh = gameObject.GetComponent<EnemyHealth>();
eh.GetComponent<health>();
eh.health = 0;
}
GameObject Wolf_run;
void Updatetwo(){
Destroy(gameObject);
}
}
the script does not do anything when the enemy reaches 0 health I want the enemy to be destroyed when it reaches zero health. im very new to coding
okay if your new I see no harm in telling you what your doing wrong.
-
you getting a component of a component, after you assign Enemy health just use eh.health, no need for this line
eh.GetComponent();
-
you set the enemy health every frame(Update runs every frame) this should really be
if(eh.health == 0)
-
UpdateTwo(its not like update, you have to call it manually) never gets called, i would call it right after
if(eh.health == 0)
-
You double assign CurTransform delete this line
curTransform = gameObject.GetComponent();
you also declare a useless variable called “wolfRun”
Scrap it.
that should just about cover it…hope it helps.
also check some C# tutorials by