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