Version: 2021.3
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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961