方式一:

private void Start()
    {
        InitPanelData();
    }
    /// <summary>
    /// 改变btn状态
    /// </summary>
    public void InitPanelData()
    {
        endPanel = transform.Find("endPanel").gameObject;

        BtnAddClick(endPanel.transform);

        endPanel.SetActive(false);
    }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
/// <summary>
  /// 改变btn状态
  /// </summary>
  • 1.
  • 2.
  • 3.

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);
      }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

 方式二:

public Button startbtn;

    void Start() {
        //开始训练
        startbtn.onClick.AddListener(delegate () {
            SceneManager.LoadScene("map1");
        });
    }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

 

作者:꧁执笔小白꧂