Input.GetMouseButton

Unity · Версия 2020.3 LTS · Scripting · Input

Input.GetMouseButton

Объявление

public static bool GetMouseButton(int button);

Описание

Возвращает информацию о том, нажата ли данная кнопка мыши.

Значения button: 0 для левой кнопки, 1 для правой кнопки, 2 для средней кнопки. Возвращает значение true, когда кнопка мыши нажата, и false, когда ее отпускают.

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 click.");
        }

        if (Input.GetMouseButton(1))
        {
            Debug.Log("Pressed right click.");
        }

        if (Input.GetMouseButton(2))
        {
            Debug.Log("Pressed middle click.");
        }
    }
}

Обновлено 17 ноября 2026 г.