system
1
So I know how to make an object destroy another object, but is it possible to have an object (in this case a prefab, if that matters) destroy itself? In this case I want it to destroy itself when it goes off the screen.
You just have to call destroy on it. If you attach something like the following:
if (your logic to check for off-screen){
Destroy(gameObject);
in a place it’ll be called in code, it’ll destroy itself.
This is the best way to destroy object itself when it goes offscreen,
//C# example
void OnBecameInvisible()
{
DestroyObject(gameObject);
}