- Home /
Destroy object destroys affects other objects?
Whenever my player object collides with a zombie object I want the player object to be destroyed. The problem I have with this is that the ground that the player is on doesn't get destroyed, but the image disappears. My player and zombie are both RigidBodies with BoxCollider2D and the ground is just a BoxCollider2D. I only call Destroy(otherObject.gameObject) in the Zombie script.
Can anyone help me figure out why this is happening? I will provide more information if necessary.
Thanks in advance!
ZOMBIE COLLIDER METHOD
void OnCollisionEnter2D(Collision2D otherObject) { if (otherObject.gameObject.tag == "Bullet") { animator.SetBool("HasBeenHit", true); } if (otherObject.gameObject.tag == "Player") { Destroy(otherObject.gameObject); } }
Why should the ground the player is on get destroyed? What do you mean by "the image disappears"? What image? Is it destroyed, or just some renderer disabled? Also, please format your code properly. Use the 101010 button to insert code bits in your posts.
Sounds like you're destroying the child object that the image is on ins$$anonymous$$d of the parent object.
The code looks right to me! you should look at other things that may be causing this behaviour.
Is the ground a child of the Player??
Your answer
Follow this Question
Related Questions
Teleport 2D Player to another room 2 Answers
the player is flying off the ramp (collider) 1 Answer
Coth physics in 2d 1 Answer
teleportation problems (2d) 1 Answer
OnTriggerEnter2D Running twice when destroying game object. 1 Answer