How i check dragging Started on first click?
right now Dragging Start on second click.
First click only created dragging object.
This is 2D game and created object shoud stay on Camera/Canvas.
Code is now:
public class Draging : MonoBehaviour
{
public bool dragging = false;
Vector3 dist;
float posX;
float posY;
void OnMouseDown()
{
dist = Camera.main.WorldToScreenPoint(transform.position);
posX = Input.mousePosition.x - dist.x;
posY = Input.mousePosition.y - dist.y;
}
void OnMouseDrag()
{
Vector3 curPos =
new Vector3(Input.mousePosition.x - posX,
Input.mousePosition.y - posY, dist.z);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(curPos);
transform.position = worldPos;
dragging = true;
print("Trigger Moving");
}
void OnMouseUp()
{
dragging = false;
print("Trigger STOP!");
}
}