1
\$\begingroup\$

The method OnMouseDown() is called once when the mouse presses my box 2d collider.

Is there a method that keeps firing while the mouse is still holding the button down inside the collider? Something like WhileMouseDown().

I could use Input.GetMouseButton(0) in the Update() method. However, this does not check if the mouse is pressing the collider.

\$\endgroup\$
2
\$\begingroup\$

You could use a combination of both OnMouseDown and OnMouseOver:

OnMouseOver is called every frame while the mouse is over the GUIElement or Collider.

You might want to set something like bool mouseIsBeingHeld = true; to track this and change it when OnMouseUp or OnMouseExit happens.


If you'd ever also want to just use Input.GetMouseButton(0), the other way to see if a Collider2D is being hovered over is via Collider2D.OverlapPoint.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .