- Home /
Drag and slide object by touch
Hello
I have a 2d tile puzzle game and want to drag and slide my object with a default speed by touch to empty place like this picture.
please help me with your java script code it's for android. thanks
Comment
Best Answer
Answer by Melih Şimşek · Dec 13, 2013 at 12:10 PM
You can use Input.Touches
// JavaScript Code Snippet
function Update () {
// Only if there are touches
if (Input.touches.Length > 0)
{
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));
}
}
}
@ alone1992 how did you create it,can you guide me with the tutorial please..??
Your answer
![](https://koobas.hobune.stream/wayback/20220613124049im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Drag an UI slider (no Unity GUI) 1 Answer
Drag object 1 Answer
Tile generation and on click. 1 Answer
Drawing Sprite from Script 0 Answers