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