Input.GetMouseButtonUp

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

Input.GetMouseButtonUp

Объявление

public static bool GetMouseButtonUp(int button);

Описание

Возвращает значение true, пока пользователь отпускает данную кнопку мыши.

Вызовите эту функцию из функции Update, поскольку состояние сбрасывается в каждом кадре. Он не вернет true, пока пользователь не нажмет кнопку мыши и не отпустит ее снова. button: 0 для левой кнопки, 1 для правой кнопки, 2 для средней кнопки.

using UnityEngine;

public class Example : MonoBehaviour
{
    // Detects clicks from the mouse and prints a message
    // depending on the click detected.

    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Debug.Log("Pressed left click.");
        }
        if (Input.GetMouseButtonUp(1))
        {
            Debug.Log("Pressed right click.");
        }
        if (Input.GetMouseButtonUp(2))
        {
            Debug.Log("Pressed middle click.");
        }
    }
}

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