Drag GameObject with Touch

Hello,
I`m new here, how can i convert mouse Input to touch Input for mobile? Thanks all!

void Update () {
        if (Input.GetKeyDown("d"))
        {
            PlayerPrefs.DeleteAll();
        }
        if (transform.position.y < 0 && a && b)
        {
            if (PlayerPrefs.GetInt("mute") == 0)
            {
                sound.PlayOneShot(hoop);
                  //GetComponent<vibrator>().enabled = true;
                 Invoke("off", 0.2f);
                Handheld.Vibrate();
            }
            winParticle.SetActive(true);
            b = false;
            Invoke("next", 1f);
        }
        if (rb.velocity == new Vector3(0, 0, 0) && a)
        {


            if (PlayerPrefs.GetInt("heart") > 1)
                PlayerPrefs.SetInt("heart", PlayerPrefs.GetInt("heart") - 1);

        
            else
                PlayerPrefs.SetInt("heart", 3);
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);



        }
        if (Input.GetMouseButtonDown(0) && !a)
        {
            touchpos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
            touchpos = Camera.main.ScreenToWorldPoint(touchpos);
        }
        if (Input.GetMouseButton(0) && !a)
        {
            Vector3 touchpos1 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10);
            touchpos1 = Camera.main.ScreenToWorldPoint(touchpos1);
            gameObject.GetComponentInChildren<SpriteRenderer>().enabled = true;
            dist =Vector3.Distance(touchpos,touchpos1)* 0.2f;
            if (dist < 0)
                dist = 0;
            if (dist > 0.6f)
                dist = 0.6f;
            rotationX = (Input.GetAxis("Mouse X"));
            transform.GetChild(0).transform.localScale = new Vector3(0.2f, dist *2.5f, 1f);
            transform.Rotate(new Vector3(0, -rotationX * 200 * Time.deltaTime, 0));
        }
        if (Input.GetMouseButtonUp(0) && !a)
        {
            a = true;
            gameObject.GetComponentInChildren<SpriteRenderer>().enabled = false;
            rb.AddRelativeForce(0, 0, 5000 * dist*200 * Time.deltaTime);
        }
    }

Best way is to break apart input gathering from input processing, rather than interleaving hard-coded calls to input throughout your logic.

You can see how I did it with my proximity_buttons package. It abstracts ALL touches into something I call MicroTouch, gathers them all up and then all my logic uses only MicroTouches, which in the editor include the mouse, but otherwise are touches from mobile, if built for mobile.

proximity_buttons is presently hosted at these locations:

https://bitbucket.org/kurtdekker/proximity_buttons

https://github.com/kurtdekker/proximity_buttons

Thank you for quick response,

Is it possible that you can give an example from the code I shared so that I can understand better?

I recommend breaking your code apart:

  • Gather all input into local variables

  • Process all input from those variables

One you have that going, adding additional sources of touches (ie., mobile, MicroTouch, joystick, whatever) is trivial.