【问题标题】:Visual Studio Code - C# extension does not recognize the Unity classesVisual Studio Code - C# 扩展无法识别 Unity 类
【发布时间】:2019-12-11 17:03:00
【问题描述】:

我正在尝试设置我的 VS Code,以便正确处理使用 Windows 10 作为操作系统的 Unity 项目。这就是我所做的:

  • 安装 Unity v.2019.3.0a2;
  • 安装 Visual Studio Code v.1.40.2;
  • 安装 C#(Visual Studio Code 扩展);
  • .Net 的安装;
  • 将 VS Code 设置为 Unity 脚本编辑器(如 here 所述);

此时我在 VS Code 工作区中导入了我的项目根文件夹,但 IntelliSense 功能不起作用。所以我读了this guide 然后我跑了:

dotnet new console
dotnet run

现在看来,IntelliSense 可以工作,但 VS Code 无法识别 Unity 类,因此,我的项目充满了错误。有没有办法修复它或导入 UnityEngine 包?

【问题讨论】:

    标签: c# .net unity3d visual-studio-code


    【解决方案1】:

    您不需要 .Net 来处理 Unity 项目。 只需安装 Microsoft .Net Framework 4.7.1 SDK 即可使您的 C# Omnisharp VS Code 扩展正常工作。什么都不用做,只要打开你的项目,一切就OK了。

    查看您的 VS Code OUTPUT->Omnisharp 日志,它会要求您安装 .Net Framework SDK

    另外,你需要至少用 Unity Editor 打开你的项目一次,否则你会在你的 VS 代码中得到很多 The name 'gameObject' does not exist in the current context [Assembly-CSharp]csharp(CS0103)The type or namespace name 'GameObject' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]csharp(CS0246) 等等错误,即使是一个可行的项目。

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      • 2021-09-02
      • 2016-01-23
      • 1970-01-01
      相关资源
      最近更新 更多