LoginSignup
8
6

More than 5 years have passed since last update.

Buttonに設定したClickイベントのコールバック関数内で呼び出し元のButtonの情報を得る

Last updated at Posted at 2017-09-23

環境

Unity2017.1.1p3

概要

インスペクター上でClick用のコールバック関数を設定した場合を想定しています
実際にButtonをClickした時に、何らかの処理中で一時押せないようにしたい場合等に、Button自体の参照が必要ですが、コールバック関数には渡ってきません
「EventSystem.current.currentSelectedGameObject」というのがありました
知りませんでした

プログラム

    public void OnButtonClick()
    {
        var button = EventSystem.current.currentSelectedGameObject.GetComponent<Button>();
        Debug.Log( "OnButtonClick:" + button.name );
    }
8
6
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
8
6