Mouse click on cubes, x,y,z?

I have a plane, with 5 cubes on it. Labelled cube1…cube5.

I also have a main camera that shows the plane in an isometric style view.

I want to be able to click the mouse on a cube and find out which cube Was clicked on and the x,y,z position the click was on the cube…it seems easy but it is hard…

How can I do this?

  • Ensure all of the cubes have box colliders
  • Use a Physics.Raycast with a ray created by Camera.main.ScreenPointToRay(Input.mousePosition)
  • Inspect the hit point on the HitInfo returned by the ray cast to find the point and the collider.gameObject to find the cube.