版本: Unity 6 (6000.0)
语言英语
  • C#

Bounds.extents

建议修改

成功!

感谢您帮助我们提升 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们确实会阅读用户提出的每项修改建议,并在适用情况下进行更新。

关闭

提交失败

由于某种原因,您的修改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提升 Unity 文档的质量。

关闭

取消

public Vector3 extents;

描述

包围盒的范围。这始终是 Bounds 的 size 的一半。

注意: 如果 Bounds.extents 任何轴上的值都为负数,则 Bounds.Contains 始终返回 False。

//Attach this script to a visible GameObject.
//Click on the GameObject to expand it and output the Bound extents to the Console.

using UnityEngine;

public class Example : MonoBehaviour { Collider m_ObjectCollider; public Vector3 m_MyScale;

void Start() { //Fetch the GameObject's collider (make sure they have a Collider component) m_ObjectCollider = gameObject.GetComponent<Collider>(); //Output the GameObject's Collider Bound extents Debug.Log("extents : " + m_ObjectCollider.bounds.extents); }

//Detect when the user clicks the GameObject void OnMouseDown() { //Change the scale of the GameObject to the size you define in the Inspector transform.localScale = m_MyScale; //Output the extents of the Bounds after clicking the GameObject. Extents change to half of the scale. Debug.Log("extents : " + m_ObjectCollider.bounds.extents); } }