유니티 RayCast 관련 - 마우스 클릭으로 판별 - 4.3 2D 용 전환

|


Unity 3D의 레이케스트를 사용해서 물체를 판별하는 방법(당연히 물체에 콜라이더 컴포넌트 적용 되야 됨)



  1.             RaycastHit hit = new RaycastHit();
  2.  
  3.        
  4.  
  5.             if (Physics.Raycast(ray.origin,ray.direction, out hit)) {
  6.                 hit.transform.gameObject.SendMessage("HandleInput");
  7.             }
  8. }


Unity 2D의 레이케스트를 사용해서 물체를 판별하는 방법(당연히 물체에 2D 콜라이더 컴포넌트 적용 되야 됨)


  1. {
  2.     RaycastHit2D hit = Physics2D.GetRayIntersection(ray,Mathf.Infinity);
  3.            
  4.     if(hit.collider != null && hit.collider.transform == thisTransform)
  5.         {
  6.                // raycast hit this gameobject
  7.          }
  8. }


아래 방법도 동일함


  1.  
  2. if(collider2D.OverLapPoint(mousePosition))
  3. {
  4. //do great stuff
  5. }
  6.  
  7.  
  8. }


Trackback 0 And Comment 0