- Home /
Question by
Basen · May 04, 2015 at 08:15 AM ·
c#unity 5touchdrag-and-drop
Drag and DoubleTap from mouse to touch???
Greetings,
I've been bashing my head over this one for the past two days, and I just can't get it to work... I've been using the mouse controls for single touch controls on mobile devices. However I've noticed some hiccups here and there and would rather use the touch controls. I've checked the entire web for a solution but none worked for me for some reason... I've pasted the code I have atm for mouse, I need help converting that for touch controls.
THANK YOU in advance!
void OnMouseDown()
{
distance = Vector3.Distance (transform.position, Camera.main.transform.position);
dragging = true;
}
void OnMouseUp()
{
dragging = false;
if ((Time.time - doubleClickStart) < 0.3f)
{
this.OnDoubleClick();
doubleClickStart = -1;
}
else
{
doubleClickStart = Time.time;
}
void Update()
{ if (dragging)
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Vector3 rayPoint = ray.GetPoint (distance);
transform.position = rayPoint;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Camera up and down on TouchField 1 Answer
Mouse and Oculus Touch Controller Inputs 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers