I wrote a script for my plane to be destroyed and explode when it collides with the terrain but it doesn’t work. The plane has a rigidbody, and I tested out with the Is Trigger option off and on. Can anyone help me out? Thanks.
var explosion : ParticleEmitter;
function OnCollisionEnter (collide : Collision)
if(collide.gameObject.tag == "Terrain")
Instantiate(explosion, transform.position, Quaternion.identity);
Is this script attached to the airplane? If that’s true, use Destroy(gameObject); since this will “suicide” the script owner - the airplane, in this case. The way you did it should work too, but you should avoid GameObject.Find because it’s too slow, and a common source of errors too.
Anyway, a possible reason for this to fail is the terrain tag: the terrain is untagged unless you explicitly tag it - and you must create the tag Terrain, since it’s not included in the default tag list.
Check the terrain tag, and if it’s ok place a debug line before the if - something like print(“Hit something”); - to refine the bug search.