Can't seem to get collision to work

So I have a rocket prefab that instantiates every time you press the spacebar. It’s supposed to be destroyed when it goes out of a camera’s view, or hits the terrain. I can’t get it to work. Take a look at my code.

#pragma strict

var terraintarget : GameObject;
private var invis : boolean = false;
private var terraincollide : boolean = false;


function OnBecameInvisible() {
	invis = true;
}

function Update(){



	if(invis === true){
		Destroy(gameObject);
	}
	if(terraincollide === true){
		Destroy(gameObject);
	}
	

}

    function OnCollisionEnter (collision : Collision) {
    	
    	if(collision.collider.name === "Ground"){
    		Destroy(gameObject);
    	}
    
    }

I tried changing it to print to the console the name of the colliders it hits, but that won’t work either.

some sanity checks first:

  • does your rocket have a collision on it? box collider, sphere, etc?
  • you are using a variable called terraincollide but never set the value to true but then you are checking if it’s true…
  • you have a public variable for targetterrain. I assume you are setting that in the inspector but never reference it in the code.
  • the terrain you are hitting, is it a unity terrain or mesh? does it have a terrain collider or other collider of shorts?
  • have you tried using == instead of === in case unity is doing something funky with datatypes?