Destroying bullet when leaving camera view

As title says, when a player firesa a projectile, how would I destroy it once it leaves camera view?

function Update () {    
  amtToMove = bulletSpeed * Time.deltaTime;    
  transform.Translate(Vector3.up * amtToMove);

  if(transform.position.y>=6.5){    
	Destroy(gameObject);	
  }
}

this destroys bullet once it’s past 6.5, however i’d idealy like the bullets to be destroyed based on the cameras current position/view

any ideas? Thanks you.

You can use OnBecameInvisible in the object’s script:

function OnBecameInvisible () {
  Destroy(gameObject);
}

An object is considered visible when it’s inside the view angle (or frustum, to be more precise) of any camera - even if it’s hidden behind some object, mountain etc. When you run it in the Editor, the Scene camera is also taken in account, thus the object may be out of the Game view and still be considered visible. Other problems may occur if you use a high top down camera to create a map: the bullet will be destroyed only when it lefts the map.

Try gameObject.renderer.isVisble

Every renderer has a variable called isVisible which will return true if the renderer is visible to any camera, and false otherwise. Adding a simple if statement like

if (!renderer.isVisible) {
     Destroy(gameObject);
}

would destroy the gameObject the moment it is not visible by the camera.

-Kith