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