Unity3D에서 2D 환경에서의 Object 선택을 위한 방법을 소개합니다.
void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 wp = Camera.main.ScreenToWorldPoint(Input.mousePosition); Ray2D ray = new Ray2D(wp, Vector2.zero); RaycastHit2D[] hits = Physics2D.RaycastAll(ray.origin, ray.direction); foreach (var hit in hits) { if (!hit.collider.gameObject.CompareTag("Coin")) continue; GameObject can = hit.collider.gameObject; can.GetComponent<Animator>().SetTrigger("Disapear"); } } }