docs.unity3d.com
    Show / Hide Table of Contents

    On Mouse Input node

    Note

    The On Mouse Input 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 Input node listens for a specific action on a user's mouse. The action doesn't need to happen on a specific GameObject's Collider. 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 Input node displays with its details in the Graph Inspector.

    Fuzzy finder category

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

    Inputs

    The On Mouse Input node has the following input ports:

    Name Type Description
    Button Mouse Button The name of the mouse button that triggers the On Mouse Input node.
    Action Press State The specific state of the mouse button that the node listens for.
    Hold The user holds down the mouse button.
    Down The user presses the mouse button.
    Up The user releases the mouse button.

    Additional node settings

    The On Mouse Input 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 Input 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 Input node listens for the user to hold the right mouse button and triggers an Instantiate Camera node. The Instantiate node clones the camera saved as the Camera1 Scene variable and assigns it to the NewCamera Scene variable. It sets a new position for the cloned camera with a Transform Set Position node, before it switches which camera renders in the Game view with the Camera Render node.

    An image of the Graph window. An On Mouse Input node with its Button and Action inputs set to Right and Hold connects its Trigger output port to the Invoke input port on an Instantiate Camera node. The Instantiate Camera node's Original input port connects to a Get Variable node's Value output port to decide which camera to clone, and gets the value for the Camera1 Scene variable. The Instantiate Camera node connects its Exit output port and its Result output port to a Set Variable node's Assign input port and New Value input port, respectively. The Set Variable node uses an inline value for its Name input to set the input from New Value as the NewCamera Scene variable. The Set Variable node connects its Assigned output port and its Value output port to a Transform Set Position node's Set input port and Target input port. It uses inline values to set the Value of the new position, then connects its On Set output port to a Camera Render node's Invoke input port. A Get Variable node, which gets the value of New Camera, connects its Value output port to the Render Camera node's Target input port.

    When the application runs, the default view in the Game view displays all three spheres in the scene.

    An image of the Game view. It displays 3 red metallic spheres in a line on a grey plane.

    When the user holds the right mouse button and triggers the On Mouse Input node, the Game view changes to focus on the middle sphere.

    An image of the Game view. It displays one red metallic sphere and the edges of a sphere on either side of the middle sphere.

    Related nodes

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

    • On Button Input node
    • On Keyboard Input node
    • On Mouse Down node
    • On Mouse Drag node
    • On Mouse Enter node
    • On Mouse Exit node
    • On Mouse Over node
    • On Mouse Up node
    • On Mouse Up As Button node
    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