macOS下的Unity使用VS Code没有语法提示的解决

Unity更新频率挺高的,拾起许久没使用的Unity,界面似乎很陌生,最高版本都到2021.1.7f1了,也强制使用UnityHub了.更新了VS Code,没有语法提示,搜索解决方案,竟然搜到自己曾写的教程,

MACOS下UNITY与VS CODE安装配置:http://1vr.cn/?p=2006

嘿嘿,今天这篇就作为前文的补充吧.安装用于Unity的VS Code步骤比较简单,首先是安装VS Code,全称Visual Studio Code,从微软官网下载安装即可,其免费且开源.

VS Code:https://code.visualstudio.com/Download

接着安装Dotnet及Momo,分别是,下载地址如下:

.NET Core SDK:https://dotnet.microsoft.com/download
Mono:http://www.mono-project.com/download/stable/

安装好后运行VS Code,到VS Code Marketplace(菜单Code->Preferences->Extensions)中安装C#扩展.

再确保Unity Preferences中External Tools指向到VS Code,至此就可以打开Unity双击C#文件使用VS Code编程了,如果这时候发现没有语法提示,并且可以在Output窗口看到如下错误信息:

omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1216,5): Error: This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. “omnisharp.useGlobalMono”:”always” in C# Extension for VS Code).

那么需要打开VS Code的设置,搜索Use Global Mono,将它的值从auto改为always,如下图:

根据提示重启VS Code即可正常使用,下面是建议安装的几个扩展插件,如Debugger for Unity,Unity Tools,Unity Code Snippets,Unity Snippets等:

好了,就写到这里,回见!

参考链接:https://code.visualstudio.com/docs/other/unity

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注