Draging an object. From script with Mouse Input to Touch Input.

Hi

I need a script that will allow me to drag an object trough the screen. I have found the folowing script on the Unity Wiki (the JS) and it suits me perfectly. That is 100% what I need ( I will modify some of the effects in the functions), BUT I need to use it on a mobile device with touch screen and this one is with mouse. I do not understand well the GetTouch input so I have failed repeatedly to combine the script from the Wiki and those examples here.

1 Answer

1

You probably want to track the first touch in Input.touches from TouchPhase.Begin through TouchPhase.Moved. You should be able to directly sub Touch.position for Input.mousePosition.

If you want to handle multi-touch correctly you’ll need to check the Touch.fingerId. To only accept input from one finger at a time make sure you only take data from the touch matching the initial fingerId, until that finger is lifted off the screen.

Great, glad you got it working!