Using raycasting to select/collide with game objects in 2D for android

I have been trying to use raycasting to select the game tiles/buttons I have created so far. Every thread and tutorial I have seen either deals with 2D PC ray casting or 3d android raycasting. I would appreciate if anyone could help me out either with pointing me in a different correct direction or helping me out with the code.

I would like to create something along the lines of:

//If there’s at least one finger on your phone and the touch just began
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
//Creates a ray at the point you are touching
ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

//If the raycast hit something
if(Physics.Raycast(ray, Mathf.Infinity)){
Debug.Log(“We Hit something”); //If we collided with something say we did
}
}

What happens when you try to run this?

One thing I see is that Camera.ScreenPointToRay() takes a Vector3, but Input.GetTouch(0).position is a Vector2. You need to use a Vector3 that contains the touch position values in x and y:

...

touchPos = Input.GetTouch(0).position;
touchPosV3 = new Vector3(touchPos.x, touchPos.y, 0);
ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);

...

It’s kind of silly since the z-value of the Vector3 is ignored anyway.