OnMouseDown and OnMouseUp but not OnMouseUpAsButton?
private void OnMouseDown()
{
print("down "+piecename);
}
private void OnMouseUpAsButton()
{
print("upbutton");
}
private void OnMouseUp()
{
print("up " + piecename);
}
just a very simple code, I do have collision2D on the object, but sometime i can have only down and up but not upbutton, is there any reasonable explanation for this
Answer by avazutaev · Mar 31, 2017 at 09:24 AM
Check out these things:
OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed.
This function is called on Colliders marked as Trigger if and only if Physics.queriesHitTriggers is true.
This function is not called on objects that belong to Ignore Raycast layer
private void On$$anonymous$$ouseDown()
{
ptest=this;
print("down "+this);
}
private void On$$anonymous$$ouseUpAsButton()
{
print("upbutton");
}
private void On$$anonymous$$ouseUp()
{
print("isSamePiece"+(ptest == this));
print("Physics"+Physics.queriesHitTriggers);
print("up " + this);
ptest = null;
}
ok, I change my code, ptest is a static field, now i assure i released on the same object, and Physics.queriesHitTriggers is true, and I do not have any function or anything to do with Raycast. I do have something do while dragging, basically following the mouse, would it make any problem?
yeap, try to disable other scripts that using mouse and check your collider marked as isTrigger
ah i find the problem, actually u don't need to release on the same object to call On$$anonymous$$ouseUp, u can release anywhere it's still going call On$$anonymous$$ouseUp.
Your answer
![](https://koobas.hobune.stream/wayback/20220612114347im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I disable mouse input completely? 3 Answers
Mouse Cursor Problems,PLEASE HELP ME,I have cursor problems 0 Answers
How to control global mouse 0 Answers
User Layer that Ignores Raycast? 2 Answers