What I’m trying to create is a pipe drip. One that will spawn within the view of the camera and fall out of view. What I’m wondering is if it is possible to destroy the game object after it has passed the view using a script.
Yes, you can check if the object is still on screen with Renderer.isVisible or Renderer.OnBecameInvisible depending on if you prefer a boolean check or a function call.
But at it’s simplest you could add this to the Update function
if (!renderer.isVisible)
Destroy (gameObject);
and it will destroy itself when it can’t be seen anymore.
The gotcha is it might destroy itself early if the object can ever be spawned off screen, but you could work around that by performing extra checks, like if it’s existed for X seconds or something.
For performance you may be better off (especially for iPhone) using a cache of droplet objects and just activate/deactivate/reuse them as opposed to an Instantiate and Destroy cycle. It’s not so bad on desktop hardware but on mobile devices the garbage collection stutter can be minimized with the enable/disable approach.