- Home /
Question by
nerf zone · Nov 19, 2014 at 06:01 AM ·
not workingbullethealth
Need Help with Health Script
Hello. It's me again with a problem. I got my health and bullet damage script from the community.
Here is the health script:
var health:float = 100;
var deadbody : GameObject;
if(health <= 0){
Destroy(gameObject);
Instantiate(deadbody, transform.position, transform.rotation);
}
and Bullet damage script :
var damage:float = 20;
function OnTriggerEnter(hit:Collider){
if(hit.tag == "Enemy"){
Debug.Log("Hit Enemy");
hit.transform.GetComponent(Nyawa).health -= damage;
}
}
The problem is, the health script doesn't destroy the gameobject and goes to negative value. Any help would be very very very appreciated! Thanks.
Comment
Is your health script missing an update function:
function Update(){
if(health <= 0){
Destroy(gameObject);
Instantiate(deadbody, transform.position, transform.rotation);
}
}
If it is, update is called each frame and can do work. An open if statement/code blocks in the desert that is code is worthless.
Your answer
Follow this Question
Related Questions
Enemy health and bullet problem 2 Answers
Do not pick item when item full 2 Answers
bullet damage problem 1 Answer
Scavenger script woe... 1 Answer
Health change than object health is not decreasing ? 2 Answers