I need the number for a second button, which should be 1: Input.GetMouseButtonDown(1). However, it doesn’t reckon that that’s its number. If I supply 0, it executes the other button, as expected. I’ve tried 2 and 3, with no luck. How do I find the correct number?
Hi @Perrorist
You can use the new Input System’s listen feature, to find the button’s name, then map it to its corresponding number using the KeyCode docs:
Mouse0 The Left (or primary) mouse button.
Mouse1 Right mouse button (or secondary mouse button).
Mouse2 Middle mouse button (or third button).
Mouse3 Additional (fourth) mouse button.
Mouse4 Additional (fifth) mouse button.
Mouse5 Additional (or sixth) mouse button.
Mouse6 Additional (or seventh) mouse button.
for example:
middleButton is Mouse2
Or you can write a simple script which prints which mouse button is pressed:
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.GetMouseButton(0))
{
Debug.Log("Pressed left btn.");
}
if (Input.GetMouseButton(1))
{
Debug.Log("Pressed right btn.");
}
if (Input.GetMouseButton(2))
{
Debug.Log("Pressed middle btn.");
}
if (Input.GetMouseButton(3))
{
Debug.Log("Pressed fourth btn.");
}
if (Input.GetMouseButton(4))
{
Debug.Log("Pressed fifth btn.");
}
if (Input.GetMouseButton(5))
{
Debug.Log("Pressed sixth btn.");
}
if (Input.GetMouseButton(6))
{
Debug.Log("Pressed seventh btn.");
}
}
}
Although I’m still curious as to the answer, I’ve resolved the reason for my question. (A button is not a button if it’s an image.)