unity detect if object goes off screen code example
Example: how to detect when a gameobject leaves the screen
void OnBecameInvisible() { Destroy(gameObject); }
void OnBecameInvisible() { Destroy(gameObject); }