Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Input.GetMouseButtonDown

マニュアルに切り替える
public static bool GetMouseButtonDown(int button);

パラメーター

説明

ユーザーがマウスボタンを押したフレームの間だけ true を返します

毎フレームこの値はリセットされるので Update 関数内でこの関数を呼び出す必要があります。 ユーザーがマウスボタンを離し、再度押すまで true を返しません。 ボタンの値は左ボタンは 0、右ボタンは 1、中ボタンは 2 になります

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { if (Input.GetMouseButtonDown(0)) Debug.Log("Pressed left click."); if (Input.GetMouseButtonDown(1)) Debug.Log("Pressed right click."); if (Input.GetMouseButtonDown(2)) Debug.Log("Pressed middle click."); } }