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.