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

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

Unity Build 錯誤:當前上下文中不存在名稱“EditorUtility”

Unity Build 錯誤:當前上下文中不存在名稱“EditorUtility”

C#
慕慕森 2023-05-14 16:38:35
我有一個非常簡單的問題。當我嘗試統一構建游戲時出現構建錯誤。當我在編輯器中運行游戲時,它工作得很好。這是控制臺中顯示的錯誤。Assets\Scripts\Pattern.cs(284,17): error CS0103: The name 'EditorUtility' does not exist in the current context現在,這是錯誤引用的代碼行:EditorUtility.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");最后,如果您認為錯誤是我沒有將正確的東西導入腳本,那您就錯了,因為我導入了這個:using System.Linq;using System.Collections;using System.Collections.Generic;using UnityEngine;using System;using UnityEditor;有誰能夠幫助我?先感謝您。編輯:執行此代碼:#if UNITY_EDITOR            EditorUtility.DisplayDialog("Meh", "You got the pattern wrong ):", "Try Again!");#endif不起作用。在構建版本中,它只是不顯示消息框,它的行為就好像這一行只是一條評論。有人可以幫忙嗎?
查看完整描述

2 回答

?
慕田峪9158850

TA貢獻1794條經驗 獲得超8個贊

你現在有錯誤的原因是,Unity 在編譯時刪除了他們為它設計的“UnityEditor”命名空間。這就是為什么當您嘗試在平臺上使用它時,“EditorUtility”將永遠不會存在于除 UnityEditor 之外的任何平臺上。因為“EditorUtility”在“UnityEditor”命名空間中。


因此,如果您想使用“EditorUtility”完成與在 Unity 編輯器中所做的相同的工作,您應該像他們一樣自己實現它。


#if UNITY_EDITOR

    EditorUtility.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");

#else

    YOUROWNCLASS.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");

#endif


查看完整回答
反對 回復 2023-05-14
?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

UnityEditor內容通常只能在編輯器中使用,因為在將游戲構建為獨立 EXE 時不能使用它。

如果您實際上是為編輯器編譯游戲,請嘗試添加預處理器指令以包含與編輯器相關的內容。

#if UNITY_EDITOR
    EditorUtility.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");
    #endif

正如@Retired Ninja 在評論中告訴我們的那樣,您還需要#if UNITY_EDITOR ... #endif在您的行周圍放置相同的指令。using UnityEditor;


查看完整回答
反對 回復 2023-05-14
  • 2 回答
  • 0 關注
  • 588 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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