To get the mouse input event in Unity, we have to create a script attached to your game object. Then add the following script to it:
using UnityEngine;
using System.Collections;
// Detects clicks from the mouse and prints a message
// depending on the click detected.
public class ExampleClass : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButtonDown(0))
Debug.Log("Pressed left button.");
if (Input.GetMouseButtonDown(1))
Debug.Log("Pressed right button.");
if (Input.GetMouseButtonDown(2))
Debug.Log("Pressed middle click.");
}
}
void Update()
{
Debug.Log("mouse: " + Input.mouseScrollDelta.y );
}
If you scroll you mouse up and down, you will get the log like:
mouse: 6.643539
mouse: 12.98123
Join the newsletter to receive the latest updates in your inbox.