0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

(3)マウスボタンを押した後の処理 GetMouseButton

Posted at

GetMouseButton簡単らしいけど、自分よく分かっていなっかたのでネットで調べたまとめと、疑問に思った事を少し実験。

Input.GetMouseButtonは、基本マウスボタンが押されているかどうかを返す。
でも押すだけじゃなくて、押し続ける、離す、左クリック、右クリック、中クリックで条件を変えて処理も変える事が出来る。

マウスを押したり、離したり

  1. GetMouseButton 空白
     マウスクリックしている間

  2. GetMouseButton Down
     マウスクリックした時

  3. GetMouseButton Up
     マウスボタンが離れた時

👆個人的に「Wクリック」が気になる。。

ネット調べた結果無いのかも。。でもあった。
Unityでシングルクリック(タップ)/ダブルクリック(タップ)のイベントを使い分ける

マウスボタンで差別化

1) Input.GetMouseButtonDown
 マウスをクリックした時
 👆どれでも、入力を受け付けるって事かな?
キャプチャ.JPG

読み間違えた?これはない。0、1、2のどれか。

1)Input.GetMouseButtonDown(0)
 クリックの時

2)Input.GetMouseButtonDown(1)
 クリックの時

3)Input.GetMouseButtonDown(2)

 クリックした時
 👆ホイールの事かな?

        if (Input.GetMouseButtonDown(2))
        {
            Debug.Log("入力受付中");
        }

ホイール押下すると正解
キャプチャ01.JPG

その他

・GetMouseButtonDownはInputクラスの関数の一つ
・bool型で返ってくるので、基本的にif文の条件式として使用するのが良い

何を覚えたか?

・Input.GetMouseButtonは押したり、離したりする動作や、左クリック、右クリックなどのボタンで設定する。
・基本if文でbool型で返ってくるので「押されたら」などで使う。
・Wクリックも頑張れば実装可能。やってないけど。。

参考にさせて頂いたサイト

[【Unity】マウスクリックを検知する方法は?GetMouseButtonDownの使い方]
(https://xr-hub.com/archives/4181)
スクリプトリファレンス
【Unity】1分でわかる!マウス関連する3つのメソッド
【Unity】マウスが左・右クリックされたときの処理を設定できるメソッド

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?