게임개발/유니티

2D 오브젝트를 클릭으로 접근하는 방법

허규남 2018. 1. 1. 18:15

Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero);


다만 해당 함수가 실행되기 위해서 해당 게임오브젝트에


위와 같이 Physics2D - BoxCollider2D를 넣어줘야만 가능함.

까먹어서 20분정도 삽질했음 ㅠㅠ


참고문서 : http://gameculture.tistory.com/23