Called on releasing the mouse button while the mouse pointer is over the Collider attached to this GameObject.
The key factor is where the mouse button is released rather than where it was initially pressed down:
OnMouseUp
is called on that collider.OnMouseUp
is not called on that collider.For button-like behavior (requiring both press and release over the same collider), use MonoBehaviour.OnMouseUpAsButton.
This event is sent to all scripts attached to the Collider. This function is not called on objects that belong to Ignore Raycast layer. This function is called on Colliders and 2D Colliders marked as trigger when the following properties are set to true:
OnMouseUp can be a coroutine.
Additional resources: OnMouseDown, OnMouseDrag.
// Register when mouse dragging has ended. OnMouseUp is called // when the mouse button is released.
using UnityEngine;
public class ExampleClass : MonoBehaviour { void OnMouseUp() { // If the user releases the mouse button while over the GameObject with this script attached, output this message Debug.Log("Drag ended!"); } }