代碼報錯 對象引用未設置為對象的實例(unity2017、VS2017)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor.SceneManagement;
public class Button1_Click : MonoBehaviour {
? ? Button mButton;
// Use this for initialization
void Start () {
? ? ? ? //獲取按鈕一
? ? ? ? Button btn = mButton.GetComponent<Button>();
? ? ? ? //給按鈕一綁定監(jiān)聽器 點擊時執(zhí)行TaskOnClick方法?
? ? ? ? btn.onClick.AddListener(TaskOnClick);
}
// Update is called once per frame
void Update () {
}
? ? void TaskOnClick()
? ? {
? ? ? ? //加載場景1
? ? ? ? NewMethod();
? ? }
? ? private static void NewMethod()
? ? {
? ? ? ? //#pragma warning disable CS0618 // 類型或成員已過時
? ? ? ? //? ? ? Application.LoadLevel(1);
? ? ? ? //#pragma warning restore CS0618 // 類型或成員已過時
? ? ? ? EditorSceneManager.LoadScene(1);
? ? ? ??
? ? }
}
這個代碼改完后還有個問題怎么解決啊,才接觸這個軟件不太明白? 調用了button的集合 但是軟件 報錯 對象引用未設置為對象的實例
已經綁定到button按鈕了啊
2019-04-24
沒 往后看。。。 public 后還要再外面選中