Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Yongs

[Unity] Mouse Picking 본문

Unity3D

[Unity] Mouse Picking

Yongs- 2019. 8. 8. 10:09

if (Input.GetMouseButtonUp(1))           //마우스 클릭 타입

{

    Ray ray;

    RaycastHit hit;

    ray = Cam.ScreenPointToRay(Input.mousePosition);

 

    if (Physics.Raycast(ray, out hit))

    {

        Vector3 offset;

        Vector3 scrSpace = Cam.WorldToScreenPoint(hit.transform.position);

        offset = hit.transform.position - Cam.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, scrSpace.z));

 

        Vector3 curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, scrSpace.z);

        Vector3 curPosition = Cam.ScreenToWorldPoint(curScreenSpace); // +offset;

        GameObject Gameobject = hit.transform.gameObject;

    }

}

 

Step1. 클릭 이벤트 발생

Step2. 광선 충돌 준비

Step3. 충돌 된 물체의 정보 확인

Step4. 원하는 이벤트 적용

'Unity3D' 카테고리의 다른 글

[Unity] Unity Log 파일확인  (0) 2019.08.08
Comments