Touch To Move iPhone

I would like a script to move a game object on the x and y axis. I tried to use the DragTransform script in the Standard Assets folder. But it doesn't move with the touch and seems laggy and on top of that it is really hard to touch... maybe iPhone mouse emulation is not very accurate.

Is there a script to do this (on iphone) or a tutorial? If not can I have some pointers on how to do this.

THANKS!!

You can use `Input.touches` which returns `deltaPosition` for each touch and apply that to your transform.

// C# Code Snippet
// Update is called once per frame
void Update () {
    // Only if there are touches
    if (Input.touches.Length > 0)
    {
        // Only work with the first touch
        // and only if the touch moved since last update
        if (Input.touches[0].phase == TouchPhase.Moved)
        {
            float x = Input.touches[0].deltaPosition.x * speed * Time.deltaTime;
            float y = Input.touches[0].deltaPosition.y * speed * Time.deltaTime;

            transform.Translate(new Vector3(x, y, 0));
        }
    }
}

and here is a JavaScript code snippet:

// JavaScript Code Snippet
function Update () {
        // Only if there are touches
        if (Input.touches.Length > 0)
        {
            // Only work with the first touch
            // and only if the touch moved since last update
            if (Input.touches[0].phase == TouchPhase.Moved)
            {
                var x = Input.touches[0].deltaPosition.x * speed * Time.deltaTime;
                var y = Input.touches[0].deltaPosition.y * speed * Time.deltaTime;

                transform.Translate(new Vector3(x, y, 0));
            }
        }
}

Please note this is just a snippet. If you want to directly copy this code please add a speed variable to your script before running.

Brilliant! Works like a charm! Thanks Andre!

Anywere touch move Object, this must be touch on object then can moveā€¦
is not?