Kill a prefab when it's no longer visible?

I’m building a basic 2D space shooter, and I’d like to automatically kill the enemies once they are no longer visible by the camera.

So I’d like to add a C# script to the enemy prefab that does something like this:

if (noLongerVisible())
    kill();

How can I do that? Thanks!

You can use Renderer.OnBecameInvisible

This method will be called when the object is no longer visible by any camera

public class DestroyOnInvisible : MonoBehaviour {
    public void OnBecameInvisible() {
         Destroy(gameObject);
    }
}

Thanks…