i want to optimise my mobile game by not showing gameObjects that are not in the camera's field. I can't do Occlusion Culling because those gameObjects are instantiated and not static.
So i used
void OnBecameInvisible(){ Renderer.enabled = false; }
void OnBecameVisible(){ Renderer.enabled = true; }
It worked but sometimes, objects remain invisible.
I tried to use:
void Update()
{
if (m_Renderer.isVisible)
{
m_Renderer.enabled = true;
Debug.Log("show");
}
else m_Renderer.enabled = false; Debug.Log("not show");
}
But the performance drops badly.
How could i fix that?
Thank you. Regards.
Unity automatically uses Frustum Culling
by default and doesn't render what the camera isn't looking at. Thus this is automatically implemented