- Home /
Question by
Content1of_akind · Dec 22, 2020 at 05:06 PM ·
editormobileclick and drag
How can I make responsive computer and touch click and drag?
This code works but it has a little delay on computer controls and higher delay on mobile touch screen controls, so its not responsive as I want it to be.
void OnMouseDown()
{
offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, transform.position.y, 0.0f));
}
void OnMouseDrag()
{
Vector3 newPosition = new Vector3(Input.mousePosition.x, transform.position.y, 0.0f);
transform.position = Camera.main.ScreenToWorldPoint(newPosition) + offset;
transform.position = new Vector2(Mathf.Clamp(transform.position.x, posXMin, posXMax), transform.position.y);
}
Comment