欢迎光临散文网 会员登陆 & 注册

Unity 按钮Button的非拖拽标准写法

2022-01-12 02:51 作者:不想努力了工作室  | 我要投稿

不要在界面上拖拽。太繁琐。

这么写

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!");

    }

}

Unity 按钮Button的非拖拽标准写法的评论 (共 条)

分享到微博请遵守国家法律