I have a destructable object in my scene. I can blow it up in 2 different ways. On mouse click and collision.
When I click the destructable object, it explodes perfectly. But when I collide with it, with my car for example it seems to not only explode but multiply so I end up having the debris from many blocks instead of just one.
When I click the block it’s fine and I only get the debris from one block.
This is the destroy code.
I read somewhere that the box collider is technically hitting the desctructable object many times so that might be the reason.
using UnityEngine;
using System.Collections;
public class Destructable : MonoBehaviour {
public GameObject debrisPrefab;
void OnMouseDown() {
DestroyMe();
}
void OnCollisionEnter( Collision collision ) {
if (collision.relativeVelocity.magnitude > 2f) {
DestroyMe ();
}
}
void DestroyMe() {
if (debrisPrefab) {
Instantiate (debrisPrefab, transform.position, transform.rotation);
}
Destroy (gameObject);
}
}