4
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 3 years have passed since last update.

Unity buttonのonclickに自作関数を設定できないときの対処法

Posted at

#動機
buttonオブジェクトのonclickコンポーネントにいつものように自作関数を設定したい!
しかしその関数がリストされない!困った!
先達が見当たらないよわよわトラブルがあったので初心者なりにメモしておきます。
#対処法
・関数のアクセス範囲をpublicにしていない
・スクリプトのアタッチされたオブジェクトを置かなければならない場所にスクリプトを直置きしている
これらは先達がカバーしてくれているので以下のリンクからどうぞ。

Unityの自作関数がボタンのOnClickに表示されない

結論から言うと
voidに設定していない
ことが原因でした。そもそもよく考えたらどこに返り値を飛ばすんだよというお話で、焦らず外から必要なものをfindして呼び出しましょう!
onclickにreturn句は禁止でvoid一択です。

4
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
4
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?