Using touch instead of mouse.

Hello there! I created a unity project on which you can drag things wherever you want. The problem is that I made it work with mouse and now I have some problems to change it to touch. Can you please help me?

bool mouseDown;

void Update()
    {
        if (mouseDown)
        {
            transform.position = new Vector3((Input.mousePosition.x / Screen.width) * 18 - 9, (Input.mousePosition.y / Screen.height) * 10 - 8.5f, 0);         
        }
    }

    private void OnMouseDown()
    {
        mouseDown = true;
    }


    private void OnMouseUp()
    {
        mouseDown = false;
    }

that probably still works, if you use single touch.

there is some cube moving example for touch in docs,

1 Like