벨로그에서 2022년 3월 27일에 포스팅한 글을 이전한 글입니다.
3D Ray에서 2D Collider 처리하기
자꾸 edge collider 충돌이 안되길래 헤맸는데 Raycast가 3D라서 2D인 edge collider는 읽지 못하는 것이었음 ...GetRayIntersection
이거 덕분인 듯?
코드
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = getCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit2D hit2D = Physics2D.GetRayIntersection(ray);
if(hit2D.collider != null) //2D collider
{
Destroy(hit2D.collider.gameObject);
}
if(Physics.Raycast(ray, out hit)) //3D collider
{
}
}
}