Convert Raycast to 2D

I wrote this script from a tutorial, which helps with touch.Inputs. The problem is, the raycasts are 3d, but my game is 2D. I tried different ways to convert the raycasts in the script to 2d, but nothing have worked.
Can someone tell me how to need to be converted?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TouchInput : MonoBehaviour {

    public LayerMask touchInputMask;
    private List<GameObject> touchList = new List<GameObject>();
    private GameObject[] touchesOld;
    private RaycastHit hit;
	// Update is called once per frame
	void Update () {
    if(Input.GetMouseButton(0) || Input.GetMouseButtonDown(0)  || Input.GetMouseButtonUp(0)) {
        touchesOld = new GameObject[touchList.Count];
                  Ray ray = GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
                  if(Physics.Raycast(ray,out hit,touchInputMask)) {
                      GameObject recipient = hit.transform.gameObject;
                      if(Input.GetMouseButtonDown(0)) {
                          recipient.SendMessage("OnTouchDown", hit.point, SendMessageOptions.DontRequireReceiver);
                      }  if(Input.GetMouseButtonDown(0)) {
                          recipient.SendMessage("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver);
                      }  if(Input.GetMouseButtonUp(0)) {
                          recipient.SendMessage("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver);
                 foreach (GameObject g in touchesOld) {
                     if(!touchList.Contains(g)) {
                         g.SendMessage("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver);

You have to use Physics2D.Raycast() instead of Physics.Raycast(). Just like this:


I haven’t tried it, so there might be some mistakes.