Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

MonoBehaviour.OnMouseUp()

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

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:

  • If you press the mouse button down anywhere, then move the cursor over the collider and release, OnMouseUp is called on that collider.
  • If you press the button over a collider, move the mouse away, and release, 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!"); } }