Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Renderer.bounds

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public var bounds: Bounds;
public Bounds bounds;
public bounds as Bounds

Description

The bounding volume of the renderer (Read Only).

This is the axis-aligned bounding box fully enclosing the object in world space.

Using bounds is convenient to make rough approximations about the object's location and its extents. For example, /renderer.bounds.center/ often is more precise "center of the object" than /transform.position/ - especially if the object is not symmetrical.

See also Mesh.bounds property that returns bounds of the mesh in local space.

	// Prints the left extreme point of the bounding volume on the x-axis
	print(renderer.bounds.min.x);
	// Prints the right extreme point of the bounding volume on the x-axis
	print(renderer.bounds.max.x);
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        print(renderer.bounds.min.x);
        print(renderer.bounds.max.x);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Example() as void:
		print(renderer.bounds.min.x)
		print(renderer.bounds.max.x)

Another example:

	// Draws a wireframe sphere in the scene view, fully enclosing
	// the object.

function OnDrawGizmosSelected () { // A sphere that fully encloses the bounding box var center = renderer.bounds.center; var radius = renderer.bounds.extents.magnitude; // Draw it Gizmos.color = Color.white; Gizmos.DrawWireSphere (center, radius); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnDrawGizmosSelected() {
        Vector3 center = renderer.bounds.center;
        float radius = renderer.bounds.extents.magnitude;
        Gizmos.color = Color.white;
        Gizmos.DrawWireSphere(center, radius);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def OnDrawGizmosSelected() as void:
		center as Vector3 = renderer.bounds.center
		radius as float = renderer.bounds.extents.magnitude
		Gizmos.color = Color.white
		Gizmos.DrawWireSphere(center, radius)

See Also: Bounds class, Mesh.bounds.