- Home /
Wont destroy child-gameObjects
When I destroy my enemy i have called bomberman It only destroys the collider by the looks of it and I just cant collide with the object anymore.
So there is a script attached to enemies->bomberman which destroys the gameObject. I assumed it would destroy enemies-bomberman->bomberman and enemies->bomberman->bombermanparticles but it doesnt.
Can anyone help?
here is the script attached to bomberman.
function OnCollisionEnter (hit : Collision){
Debug.Log("Colliding with an object: " + hit.collider.gameObject.name);
if(hit.collider.gameObject.name == "ball" || hit.collider.gameObject.name == "dbz_ball(Clone)"){
damage += 1;
}
health = maxhealth - damage;
redColor = damage/20;
Debug.Log("health is: " + health);
//Debug.Log("red color is: " + redColor);
//enemyRenderer.renderer.material.color.r = redColor;
//enemyRenderer.renderer.material.color.b = 0;
//enemyRenderer.renderer.material.color.g = 0;
var color : Color = new Color(redColor, 0.0f, 0.0f);
enemyRenderer.renderer.material.color = color;
audio.Play();
if(health < 1){
health = 0;
var clone = Instantiate(explosion, transform.position, transform.rotation);
Debug.Log("gameObject should be destroyed");
Destroy(gameObject.transform);
Destroy(gameObject.gameObject);
Destroy(gameObject);
Destroy(clone.gameObject, 2);
}
}
Answer by Tourist · Jan 24, 2013 at 04:55 PM
Destroy(gameObject.gameObject); Destroy(gameObject);
are the same instruction.
I think u mean gameObject.transform.parent.gameObject
ok now I somehow got it working I have a new problem. It ONLY deletes the child objects but not itself even when I call Destroy(gameObject);
name each object with an unique name, and use debug log to see which gameobject you are deleting