方式一:
private void Start() { InitPanelData(); } /// <summary> /// 改变btn状态 /// </summary> public void InitPanelData() { endPanel = transform.Find("endPanel").gameObject; BtnAddClick(endPanel.transform); endPanel.SetActive(false); }
/// <summary>
/// 改变btn状态
/// </summary>
public void BtnAddClick(Transform trans)
{
Button restBtn = trans.Find("restBtn").GetComponent<Button>();
Button quitBtn = trans.Find("quitBtn").GetComponent<Button>();
restBtn.onClick.AddListener(RestClick);
quitBtn.onClick.AddListener(QuitClick);
}
/// <summary>
/// 按钮的事件
/// </summary>
public void RestClick()
{
//SceneManager.LoadScene(0);
}
方式二:
public Button startbtn; void Start() { //开始训练 startbtn.onClick.AddListener(delegate () { SceneManager.LoadScene("map1"); }); }