Firstborn/Library/PackageCache/com.unity.visualscripting@1.../Documentation~/vs-nodes-events-on-mouse-in...
Schaken-Mods b486678290 Library -Artifacts
Library -Artifacts
2023-03-28 12:24:16 -05:00

4.9 KiB

On Mouse Input node

Note

The On Mouse Input [!includenodes-note-manual]

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. [!includenodes-desc-end]

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 [!includenodes-inputs]

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 [!includenodes-additional-settings]

[!include[nodes-coroutine](./snippets/nodes-coroutine.md)]
Name Type Description

Outputs

The On Mouse Input [!includenodes-single-output]

[!include[nodes-input-output-trigger](./snippets/input-manager/nodes-input-output-trigger.md)]
Name Type Description

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.

[!includenodes-related] On Mouse Input node: