Unity 按钮Button的非拖拽标准写法
不要在界面上拖拽。太繁琐。
这么写
public class ClickExample : MonoBehaviour {
private void Avake(){
private void Awake()
{
Button btn = this.GetComponent<Button>().GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
Debug.Log("You have clicked the button!");
}
}