大家好,我是佛系工程師☆恬靜的小魔龍☆,不定時更新Unity開發技巧,覺得有用記得一鍵三連哦。
一、前言
首先,看一下跟我是不是類似的問題:
缺少命名空間引用的問題。
類似的問題有:
The type or namespace name `MySql’ could not be found. Are you missing an assembly referen
The type or namespace name ‘JWT’ could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name ‘Newtonsoft’ could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name ‘****’ could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name ‘BurstCompile’ could not be found (are you missing a using directive or an assembly reference?)
UP是從Visual Studio的NuGet包管理器直接安裝的插件集,在Visual Studio是沒有報錯的,但是在Unity中會報錯。
二、原因分析
這個主要原因以下幾個友善:
1、Unity的版本問題,老版本無法支援新的依賴庫。
2、Unity的目标架構庫不支援.Net的架構庫
3、Unity中沒有加入這個dll
三、解決問題
知道問題了就好解決了。
3-1、Unity版本問題
如果是Unity 的版本問題就更新版本
3-2、Unity不支援目标架構庫
如果是Unity的目标架構庫不支援.Net的架構庫。
在Unity編輯器中,點選File→Build Settings→Player找到Api Compatibility Level:
将.NET Standard 2.0改成.NET 4.x。
安裝.NET 4.6架構的,可以改成4.6。
3-3、Unity沒有導入dll
有童鞋會說了:我Unity目标架構庫、Unity的版本都沒有問題,但是還有報錯怎麼辦呢。
那就要根據這個缺少的程式集去找到對應的dll檔案,然後放到Unity的Plugins檔案夾中:
比如說我缺少JWT和Newtonsoft的程式集,我就找到了對應的dll檔案:
放到Unity的Plugins檔案夾中: