Reputation: 1501
I'm looking for events or a code that will give me information that gameobject entered in the main camera screen and then leaves the screen so i can destroy it.
What i'm doing is a top down game which is moving forward all the time... some objects are spawned far away so i want them to move when they enter in the game screen and after leaving the screen destroy them.
i tried this event but it's triggered before game object enters in the screen... i saw some comments that rendering engine is triggering this event for shadow rendering bla bla... https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnBecameVisible.html
Upvotes: 0
Views: 384
Reputation: 1283
On top of OnBecomeVisible
you also have other options such as OnWillRenderObject, Renderer.isVisible
You can also calculate whether an object's bounding box falls within the camera's view frustum, using GeometryUtility.TestPlanesAABB
Upvotes: 1