destroy gameobject if it is out of terrain

hello together

i cant find out how to destroy an object when it is out of the terrain.

i got this on an empty gameobject:

function falling() {
    var instance : GameObject = Instantiate(Resources.Load("Cube"));
    transform.position.x=930;
    transform.position.y=11;
    transform.position.z=1074;
    
}

InvokeRepeating("falling", 0, 3);

and this on the Cube prefab:

function  OnCollisionEnter  (collisionInfo : Collision) {
 if (collisionInfo.gameObject.tag == "Terrain"){
 	//
 	audio.Play();
 	Debug.Log ("Hello");
 }
}

the cubes are bouncing around and i want to destroy them when the y position is lower than the terrains y position.

Inserting a conditional statment is all you need. There are many other ways to do this though. (ie)

var terrainH : float;

function Update () {
    if(transform.position.y <= - terrainH) {
    Destroy (gameObject);
    }
}

Make note of the third operator i used. The subtract/negative ( - ) is only needed if your kill position.y is less than 0.0
In other words less than equals negative terrainH. :slight_smile: