Unity使用时遇到的问题

如果 Unity 启动过程中提示有compilation errors

进入安全模式,查看控制台报错,解决对应脚本错误

控制台报错没有错误信息:

查看Unity日志文件,位于

C:/Users/xxx/AppData/Local/Unity/Editor/Editor.log

搜索error, 然后解决相关错误,一般是文件缺失。

文件缺失:

unity 打开项目Fatal error! 显示无权访问d3dcompiler_47.dll

https://blog.csdn.net/qq_29245693/article/details/115576107

下载对应dll文件放在System32对应文件夹中

编译错误

unity 提示The script don‘t inherit a native class that can manage a script 或 no Monobehaviour scripts in the file, or their names don't match the file name

注意c#和java一样public类的名字需要和文件名相同

另外注意需要基于 Unity 已有类实现否则 Unity 编译不出来

最后命名空间不要引入 Unity 无法识别的空间。这时会报

unity 3D error CS0234: The type or namespace name `***' does not exist in the namespace

VScode 编写 Unity 没有代码补全

查看控制台OmniSharp Log 应该会报错:

The reference assemblies for . NETFramework, Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download . NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

这时需要到.net官网下载v4.7.1的developer pack, 安装后添加注意环境变量

最后要注意返回项目中调出vscode的控制台ctrl + shift + P 使用 Omnisharp: select project 重新加载项目即可。

参考链接

Windows Unity项目打包后打开闪退

查看Unity详细崩溃信息

具体位置在

C:/Users/xxxx/AppData/Local/Temp/公司名称/项目名称/error.log

若没有报错日志需要在build settings中设置一下。