public Bounds bounds ;

Description

The world space bounding volume of the collider (Read Only).

Note that this will be an empty bounding box if the collider is disabled or the game object is inactive.

using UnityEngine;

public class ColliderBounds : MonoBehaviour { Collider m_Collider; Vector3 m_Center; Vector3 m_Size, m_Min, m_Max;

void Start() { //Fetch the Collider from the GameObject m_Collider = GetComponent<Collider>(); //Fetch the center of the Collider volume m_Center = m_Collider.bounds.center; //Fetch the size of the Collider volume m_Size = m_Collider.bounds.size; //Fetch the minimum and maximum bounds of the Collider volume m_Min = m_Collider.bounds.min; m_Max = m_Collider.bounds.max; //Output this data into the console OutputData(); }

void OutputData() { //Output to the console the center and size of the Collider volume Debug.Log("Collider Center : " + m_Center); Debug.Log("Collider Size : " + m_Size); Debug.Log("Collider bound Minimum : " + m_Min); Debug.Log("Collider bound Maximum : " + m_Max); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961