创建测试脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class myTest : MonoBehaviour
{
// Start is called before the first frame update
public Button _codeBindBtn = null;
void Start()
{
if (_codeBindBtn != null)
{
_codeBindBtn.onClick.AddListener(onCodeBindBtnClick);
}
}
// Update is called once per frame
void Update()
{
}
public void onCodeBindBtnClick()
{
Debug.Log("code bind click");
}
public void onEditorBindBtnClick()
{
Debug.Log("editor bind click");
}
}
将脚本挂载到载体,并绑定按钮

通过下面的代码绑定按钮点击事件
_codeBindBtn.onClick.AddListener(onCodeBindBtnClick);
也可以通过编辑器的设置绑定

1万+

被折叠的 条评论
为什么被折叠?



