docs.unity3d.com
    Show / Hide Table of Contents

    On Mouse Down node

    Note

    The On Mouse Down node is an Input Manager node. For more information about how to use the Input Manager with Visual Scripting, see Capture user input in an application.

    The On Mouse Down node listens for a mouse click action on a specific GameObject in your application. It triggers the next node connected to it after the action occurs in the application. It doesn't send or receive any other data.

    An image of the Graph window. An On Mouse Down node displays with its details in the Graph Inspector.

    Fuzzy finder category

    The On Mouse Down node is in the Events > Input category in the fuzzy finder.

    Inputs

    The On Mouse Down node has one input port:

    Name Type Description
    Target GameObject The GameObject that the user needs to click with their mouse to trigger the On Mouse Down node.

    Additional node settings

    The On Mouse Down node has additional settings. Access these settings from the Graph Inspector:

    Name Type Description
    Coroutine Toggle Enable Coroutine if you want Visual Scripting to run this node and any of its connected nodes as a coroutine. Coroutine nodes don't execute all their code in a single frame, so they can spread an effect over several frames. Coroutines can also help optimize your code. For more information on coroutines, see the Unity User Manual section on Coroutines.

    Outputs

    The On Mouse Down node has one output port:

    Name Type Description
    Trigger Output Trigger The control output port. Make a connection to specify what Visual Scripting should do after the configured Input event occurs in your application.

    Example graph usage

    In the following example, the On Mouse Down node listens for a click action on the GameObject where the graph runs. When a user clicks the GameObject, the On Mouse Down node triggers the GameObject Instantiate node. The Instantiate node creates a new GameObject, based on the Ball Prefab. It creates the Ball at a specific Position. It uses the Transform Get Local Rotation to match the new GameObject's Rotation to the GameObject where the Script Graph runs. Then, the graph adds a Rigidbody component to the new GameObject, and uses a Rigidbody Add Force node to add an Impulse force.

    An image of the Graph window, that displays an On Mouse Down node connected to the Invoke trigger input port on a GameObject Instantiate node. The Instantiate node uses inline values for its Original and Position, and takes its Rotation input from a Transform Get Local Rotation node targeting the parent GameObject of the Script Graph. The Instantiate node triggers a GameObject Add Component node, which adds a Rigidbody component to the newly-created GameObject. The Add Component node triggers a Rigidbody Add Force node, which uses the new Rigidbody component as its Target and inline values to apply an Impulse force.

    When the user clicks the mouse button, the Script Graph creates a new Ball GameObject and sends it towards the camera.

    An image of the Game view, that displays two instantiated Ball GameObjects flying towards the camera in a basic scene.

    Related nodes

    The following nodes are related or similar to the On Mouse Down node:

    • On Button Input node
    • On Keyboard Input node
    • On Mouse Drag node
    • On Mouse Enter node
    • On Mouse Exit node
    • On Mouse Input node
    • On Mouse Over node
    • On Mouse Up node
    • On Mouse Up As Button node
    In This Article
    • Fuzzy finder category
    • Inputs
    • Additional node settings
    • Outputs
    • Example graph usage
    • Related nodes
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023