I am needing to get every renderer inside of a BoxCollider(Trigger), I was just wondering how this would be possible, I plan to have these all around my level to create a custom occlusion culling system (since im too poor to afford unity pro), so I only need to get the renderers once at the very start of the game.
Thanks in advance!
What you’re looking for is Bounds.Contains. The method checks if a position is within some bounds, such as the bounds of a box collider:
Vector3 pos = someRenderer.transform.position;
Bounds bounds = myBoxCollider.bounds;
bool rendererIsInsideTheBox = bounds.Contains(pos);
Of course, if you’re going to include renderers that are partially inside the bounds of the box, you can check the bounds of the renderer (renderer.bounds), and see if the renderer intersects the bounds of the box:
Bounds rendererBounds = someRenderer.bounds;
Bounds colliderBounds = myBoxCollider.bounds;
bool rendererIsInsideBox = colliderBounds.Intersects(rendererBounds);
Hope that helps!