#on mouse drag doesnt work

1 messages · Page 1 of 1 (latest)

misty coral
#
private void OnMouseDrag()
{
  Debug.Log("Gets dragged");
}
#

i have a special problem with this function

#

it is somehow only working after i slighly move the object in the inspector

#

after that the function works just fine

#

also if this helps its in 2d space

cerulean glen
#

talking about this?

#

so you've got an object that you're clicking on in game, right?

misty coral
#

the even more wierd thing is that on some objects it works and on some it doesnt

#

wait

#

i will record it

cerulean glen
#

So some objects don't work, but then you move them on any axis and now they work?

cerulean glen
#

If you're moving them on the z axis I could see how maybe that could affect it, but only if something else was covering it up and now it's not

cerulean glen
#

What if you slightly move a box and then switch to selecting a different game object?

#

Then drag the box

misty coral
#

I dont really understand

#

So I should move the box via code and then?

#

I will problaly just do a custom solution since its kinda buggy and I dont have the whole day to fix it

misty coral
#
private void Update()
{
  if (Input.GetMouseButton(0))
  {
    RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
    if(hit.collider == null) return;
    if(hit.transform == transform) Debug.Log("Is Dragging"); //<--- Code here
  }  
}
#

This is what I come up with