Physics.OverlapBox

유니티 Scripting API
https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html

 

Collider[] OverlapBox
(
    Vector3 center, 
    Vector3 halfExtents, 
    Quaternion orientation = Quaternion.identity, 
    int layerMask = AllLayers, 
    QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal
);

 

center Center of the box.
halfExtents Half of the size of the box in each dimension.
orientation Rotation of the box.
layerMask A Layer mask that is used to selectively ignore colliders when casting a ray.
queryTriggerInteraction Specifies whether this query should hit Triggers.

 

Vector3 중심

halfExtents 크기의 '절반'

orientation 방향(Rotation). forward 값을 말함.

layerMask 레이어 마스크

queryTriggerInteraction

 

 

using UnityEngine;  
  
public class ManualCollision : MonoBehaviour {  
  
    public Collider[] colls;  
    public Vector3 boxSize = new Vector3(2, 2, 2);  
  
    void Update () {  
        colls = Physics.OverlapBox(transform.position, boxSize * 0.5f, transform.rotation);  
    }  
  
    void OnDrawGizmos()  
    {  
        Gizmos.matrix = transform.localToWorldMatrix;  
        Gizmos.color = Color.yellow;  
        Gizmos.DrawWireCube(Vector3.zero, boxSize);  
    }  
} 

 

위와같이 기즈모랑 같이 사용하면 좋다.

OverlapBox는 크기의 사이즈의 절반이고 Gizmo는 사이즈를 그대로 넘겨야한다. 주의할 것.

 

 

 

 

 

 

댓글

Designed by JB FACTORY