Skip to content

格式

typescript
Physics.OverlapBox(center, halfExtents, orientation, mask, query_trigger?)

所属类: Physics

描述

检测位于指定盒体区域内的碰撞体。

参数

参数名类型描述
centerVector3指定盒体区域的中心点坐标
halfExtentsVector3指定盒体区域的半边长
orientationQuaternion指定盒体区域的旋转
masknumber指定要检测的碰撞体所在的层
query_trigger?QueryTriggerInteraction该查询是否应该命中触发器

返回值

类型描述
Collider|undefined与给定盒体重叠的碰撞体

代码示例

typescript
OnUpdate(): void {

    let center = this.transform.position;
    let halfExtents = new Vector3(1, 1, 1);
    let orientation = Quaternion.identity;
    let colliders = Physics.OverlapBox(center,halfExtents,orientation,0);
        
    colliders.forEach((collider)=>{
        Debug.Log("Collider: " + collider.name);
    });
        
}