- Home /
Android Object Drag With Touch Problem
So, as the title says, i have a problem with moving/darging and object with touch... I was actually succesful at draging the object BUT the thing is, when i drag the object, it doesn't quite have the same position as the touch position...
To be more specific and less confusing xD heres an image of the example :P
I have the script attached to the object i want to drag, and this happens:
This is the Script I attached to the object:
using UnityEngine;
using System.Collections;
public class ButtonMover : MonoBehaviour {
//FixedUpdate is called once per fixed time step
void FixedUpdate()
{
if (Input.touchCount > 0) {
Vector3 _deltaPosition = Input.GetTouch (0).deltaPosition;
switch(Input.GetTouch (0).phase)
{
case TouchPhase.Began:
break;
case TouchPhase.Moved:
Drag (_deltaPosition);
break;
case TouchPhase.Ended:
break;
}
} else {
}
}
void Drag(Vector3 _deltaPosition)
{
this.transform.localPosition = new Vector3(_deltaPosition.x, 0, 0);
}
}
Pweeseee Hewp Meeee :3?
example.jpg
(335.3 kB)
Comment