- Home /
Getting all objects inside a Trigger
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!
Not an answer but if you are any good at 3D modeling or just have a good basic knowledge and good ideas then check out this months "Unity Art Challenge", you can win a pro licence :
Just though I'd let you know just in case, good luck if you do enter!!!
Answer by Baste · Dec 03, 2014 at 11:22 PM
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!
I need this to work with a mesh collider (is convex). I understand that the Bounds actually have a cube shaped bounds, right? So how can I use Bounds whith a mesh collider?