2015-10-08 103 views
-2

我有這樣的腳本:如何檢查GetComponent()是否被點擊?

Button button = GameObject.FindGameObjectWithTag("MainCanvas").GetComponentInChildren<Button>(); 

而且在該腳本的Update()函數,我願做這樣的事情:

if button clicked { // do something } 

請有人可以解釋我怎麼能做到這一點?

回答

1

不要這樣做!

改爲使用Inspector。選擇你的按鈕,找到按鈕組件,導航到OnClick()部分,選擇你想與之交互的GameObject,在可用插槽上拖放,然後找到合適的功能。

Button componen