Description
The GetLocalBounds
method of the GameObject
class returns the local bounding box of the game object. This bounding box is calculated based on the object's local space, which means it is relative to the object's own transform, not taking into account any parent transforms or world space positioning.
Note: This method is slow and somewhat inaccurate, so it is not recommended to call it every frame.
Usage
Use the GetLocalBounds
method when you need to determine the local bounding box of a GameObject
for purposes such as collision detection, visibility checks, or spatial queries within the object's local space.
Since this method can be slow and inaccurate, consider caching the result if you need to use it frequently, or only call it when necessary.
Example
// Example of using GetLocalBounds
GameObject myObject = new GameObject();
BBox localBounds = myObject.GetLocalBounds();
// Use the localBounds for further processing
Vector3 size = localBounds.Size;
Vector3 center = localBounds.Center;
// Example: Check if a point is within the local bounds
Vector3 point = new Vector3(1, 1, 1);
bool isInside = localBounds.Contains(point);