I have a Parent GameObject which I added a collider, and his grandchild has also a collider, when I enable the collider trigger of his grandchild, the parent GameObject disappears? Is this a bug? if not how would you go and fix it, so it does not disappear.
1 Answer
1I told it to avoid its grandparent. Here’s the new code.
void OnTriggerEnter(Collider asteroid) {
if (asteroid.name != transform.parent.parent.name) {
var spawnSpot = asteroid.transform.position;
Destroy(asteroid.gameObject,0.01f);
GameObject newObj = Instantiate(explosion, spawnSpot, Quaternion.identity) as GameObject;
newObj.transform.parent=transform;
newObj.tag = "Clone";
}
}
Had it tested and it works. Asteroids can hit planet, and Asteroid destroyed and debris appear.
– d112570Nice, that makes sense. Although, that means that the OnTriggerEnter method is getting called repeatedly because it's detecting a collision and that's probably not performance friendly. Think about it happening when you have multiple instances of this going on.
– ThePunisher
Is the parent object set to die/destroy itself on a collision? If so, are these two colliders in contact?
– AspirerYou're using a script somewhere I'm sure. Post the script please.
– clunk47