在2D模式下同样使用射线进行碰撞检测,注意被检测的物体需要添加碰撞盒。
if (Input.GetMouseButtonDown(1)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { Debug.Log("Target Position: " + hit.collider.gameObject.transform.name); // Do something.. } }

Comments | NOTHING