I have two of the same prefabs colliding and when they hit I want them both to delete. I can only ever get one to delete and not the other. how do I do that?
In C#
void OnCollisionEnter(Collision collision) {
Destroy(collision.collider.gameObject);
Destroy(gameObject);
}
In Javascript
function OnCollisionEnter(collision : Collision) {
Destroy(collision.collider.gameObject);
Destroy(gameObject);
}
Try this script: var object1 : Transform ; var object2 : Transform ; function Update () {
function OnTriggerEnter (){
Destroy(object1.gameObject); Destroy(object2.gameObject);
}
}
add a script to the prefab that does this:
function OnTriggerEnter(other : Collider) {
var destructable = other.GetComponent("Destructable");
if (destructable != null)
GameObject.Destroy(gameObject);
}
and is named Destructable.js. Now make sure your objects have a collider that is set to trigger and a rigidbody, otherwise there will be no collision/trigger at all.