Trying to fire a bullet which should destroy a box. I don’t necessarily need an animation, I just want the box to disappear. I attached this script to a bullet prefab which spawns an object called Bullet(clone)
var Box : String = “Box”;
function OnCollisionEnter(theCollision : Collision){
if(theCollision.Rigidbody.name == Box){
Destroy(theCollision.Rigidbody);
}
}
I’ve tried this without the var Box : String = “Box”; bit, I’ve tried switching it up so that “Box” has the code on it and checks for a collision with “Bullet(clone)”, and no matter what, the box never disappears. Also tried doing it with Gameobject instead of Rigidbody. Still no dice. What did I do wrong?
var Box : String = "Box";
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == Box){
Destroy(theCollision.gameObject);
}
}
Destroy(theCollision.rigidbody) just destroy the rigidbody of the object, not the game object itself. You should use Destroy(theCollision.gameObject) instead.
Be also sure that both the bullet and your box has Colliders, and none are triggered.