So I have an animated cannonball, which i want to hit and wall, and then the wall to be destroyed.
function OnCollisionEnter(collision : Collision)
{
if (collision.gameObject.tag == “CannonBall”)
{
Destroy(collision.gameObject);
}
}
This is what i have, but i want to destroy the wall the cannon ball hits and the cannon ball.
?
First off, that code is indeed in a script attached to the wall right? I would do it the other way around (attach the script to the cannon ball, which then finds a “wall” tag on collision), but it doesn’t matter too much.
The way you have it written, the wall will destroy the cannonball because collision.gameObject is the object that is colliding (the cannonball) with the object in your script (the wall). If you want to destroy the wall you have to do: