Find the closet object to where the screen touched.

I am trying to find a way to return the closest objected to where I touched on the the screen.

I am making a crossword game and make the game play intuitive is proving more difficult then expected lol.

Are there any built in functions that will return the closest object to a screen touch or a mouse click into Unity?

A screen touches and mouse positions are 2D coordinates in screen space. Your game objects live in world space. So your screen touch represents an infinite number of points on a ray into you world space. The typical solution to the problem you outline is to find the game object that is under the touch or mouse position. This is usually done by Physics.Raycast(). There are numerous examples of using Physics.Raycast() on Unity Answers.

If you really need to find the closest, then you will need to generate a point in world space. If your camera plane is perpendicular to the plane of your game (crossword puzzle), then you can use the distance between the two planes and use Camera.ScreenToWorldPoint() to find the world position. Then you need to cycle through your list of game objects comparing distances to find the nearest one.

If the camera plane and the playing surface are not parallel, then you can use Unity’s mathematical Plane class to construct a plane and use Plane.Raycast() to find the point in world space.