亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

“GameObject”類型的對象已被銷毀,但您仍在嘗試訪問它

“GameObject”類型的對象已被銷毀,但您仍在嘗試訪問它

C#
30秒到達戰場 2021-11-21 09:59:52
所以我正在開發一款跑酷游戲,它幾乎完成了。問題是我正在測試暫停面板,當玩家觸摸僵尸時,暫停面板出現,我通過按下重新啟動按鈕再次重新啟動游戲。但是當我再次觸摸僵尸面板時,面板沒有出現并給我標題中的錯誤。我被卡住了,任何幫助將不勝感激。這是代碼,我引用了錯誤發送給我的行:[SerializeField]private GameObject pausePanel;[SerializeField]private Button RestartGameButton;[SerializeField]private Text ScoreText;private int score;void Start (){    pausePanel.SetActive(false);    ScoreText.text = score + "M";    StartCoroutine(CountScore());}IEnumerator CountScore(){    yield return new WaitForSeconds(0.6f);    score++;    ScoreText.text = score + "M";    StartCoroutine(CountScore());}void OnEnable(){    PlayerDeath.endgame += PlayerDiedEndTheGame;}void OnDisable(){    PlayerDeath.endgame += PlayerDiedEndTheGame;}void PlayerDiedEndTheGame(){    if (!PlayerPrefs.HasKey("Score"))    {        PlayerPrefs.SetInt("Score", 0);    }    else    {        int highscore = PlayerPrefs.GetInt("Score");        if(highscore < score)        {            PlayerPrefs.SetInt("Score", score);        }    }    pausePanel.SetActive(true); //this is the line that error sends me but I cant figure it out because I didnt try to destroy the panel in the first place.    RestartGameButton.onClick.RemoveAllListeners();    RestartGameButton.onClick.AddListener(() => RestartGame());    Time.timeScale = 0f;}public void PauseButton(){    Time.timeScale = 0f;    pausePanel.SetActive(true);    RestartGameButton.onClick.RemoveAllListeners();    RestartGameButton.onClick.AddListener(() => ResumeGame());}public void GoToMenu(){    Time.timeScale = 1f;    SceneManager.LoadScene("MainMenu");}public void ResumeGame(){    Time.timeScale = 1f;    pausePanel.SetActive(false);}public void RestartGame(){    Time.timeScale = 1f;    SceneManager.LoadScene("Gameplay");}
查看完整描述

1 回答

?
動漫人物

TA貢獻1815條經驗 獲得超10個贊

我找到了解決方案。這是 OnDisable 方法的一個簡單錯誤。我刪除了 += 符號并用 -= 符號更改了它,因為它在應該禁用時啟用了該事件。


查看完整回答
反對 回復 2021-11-21
  • 1 回答
  • 0 關注
  • 372 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號