- Home /
object does not destroy
i made this script but the object is not destroyed when the hp = 0 or -. i dont know whats i did wrong and i hope tha you can help me.
here is my script :
var hitPoints = 100; var bulletDamage = 100;
function OnCollisionEnter(coll:Collision){
if(coll.gameObject.tag=="bullet") { hitPoints -= bulletDamage; }
if (hitPoints <=0){ Destroy(gameObject); } }
Have you verified (using debugger or Debug.Log) that hitPoints does reach 0?
Answer by AngryOldMan · Mar 09, 2011 at 02:43 AM
var hitPoints = 100; var bulletDamage = 100;
function OnCollisionEnter(coll:Collision) {
if(coll.gameObject.tag=="bullet") { hitPoints -= bulletDamage; if (hitPoints <=0) { Destroy(gameObject); } } }
it was right you just have to reaarange some stuff. a possibly more accurate method of doing it would be
function OnCollisionEnter(coll:Collision) { if(coll.gameObject.tag=="bullet") { hitPoints -= bulletDamage; } }
function Update () { if (hitPoints <= 0) { Destroy(gameObject); } }
try to keep your scripting neat and these kind of mistake will be easier for you to spot.