Hi,
I search about this issue for a long time but haven't found the clear answer yet.
I looked all official and user tutorials but still cannot find the clue.
What I did was following very last bit of the tutorial below (21:05 ~ 22:44) and made my object to move exactly like what it is on the video.
But from this point, what I want to do is to make the object moves depends on the amount of dragging, not tracking my finger.
How can I move the object with touching anywhere on screen and drag? I do not want the object to be hidden by my finger and also not jumping to the point where I touch. Is it possible to make the object stay where it was and move by dragging when my finger is on the screen?
thanks for reading and I hope can find good solution.
official tutorial video link is here (by Hutong games):
+ oh, and I also found the code which is exactly what I want to do (but this is for mouse?) add this on here might help you to understand what I am looking for:
using UnityEngine;
using System.Collections;
public class MouseDrag : MonoBehaviour {
private Vector3 startPos = Vector3.zero;
private Vector3 endPos = Vector3.zero;
private Vector3 targetPos = Vector3.zero;
private bool isClicked = false;
void Update()
{
DragObject();
}
void DragObject()
{
if (Input.GetMouseButtonDown(0))
{
startPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
isClicked = true;
}
if (isClicked)
{
if (Input.GetMouseButton(0))
endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
targetPos = endPos - startPos;
startPos = endPos;
targetPos = new Vector3(targetPos.x, targetPos.y, 0);
transform.position += targetPos;
}
}
}