---
title: "Detecting Mouse Clicks"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting.md?language=en&version=2019.3"
standalone_markdown_url: "https://learn.unity.com/tutorial/onmousedown.md?language=en&version=2019.3"
previous_title: "GetAxis"
previous_url: "https://learn.unity.com/course/beginner-scripting/tutorial/getaxis-o?language=en&version=2019.3"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting/tutorial/getaxis-o.md?language=en&version=2019.3"
next_title: "GetComponent"
next_url: "https://learn.unity.com/course/beginner-scripting/tutorial/getcomponent?language=en&version=2019.3"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting/tutorial/getcomponent.md?language=en&version=2019.3"
difficulty: beginner
duration_minutes: 5
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2021.3"
    url: "https://learn.unity.com/tutorial/onmousedown.md?language=en&version=2021.3"
  - name: "2019.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/course/beginner-scripting/tutorial/onmousedown.md?language=en&version=4.x"
last_updated: "2026-09-30T20:45:13.000Z"
---

# Detecting Mouse Clicks

Learn how to detect mouse clicks on Collider components and GUI elements in your scenes.

How to detect mouse clicks on a Collider or GUI element.

Previous: [GetAxis](https://learn.unity.com/tutorial/getaxis-o?projectId=5c8920b4edbc2a113b6bc26a)

Next: [GetComponent](https://learn.unity.com/tutorial/getcomponent?projectId=5c8920b4edbc2a113b6bc26a)

## OnMouseDown

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/4bf93d62-14a2-41f5-b35d-507a5d361e65_U_Beginner_17_OnMouseDown.mp4)

## **MouseClick**

```csharp
using UnityEngine;
using System.Collections;

public class MouseClick : MonoBehaviour
{

    private Rigidbody rb;

    private void Awake()
    {
        rb = GetComponent<Rigidbody>();
    }

    void OnMouseDown ()
    {
        rb.AddForce(-transform.forward * 500f);
        rb.useGravity = true;
    }
}
```
