简体   繁体   English

Visual Studio Code - C# 扩展无法识别 Unity 类

[英]Visual Studio Code - C# extension does not recognize the Unity classes

I'm trying to set up my VS Code in order to properly work with a Unity project using Windows 10 as OS.我正在尝试设置我的 VS Code,以便使用 Windows 10 作为操作系统正确处理 Unity 项目。 This is what I've done:这就是我所做的:

  • Installation of Unity v.2019.3.0a2; Unity v.2019.3.0a2安装;
  • Installation of Visual Studio Code v.1.40.2;安装 Visual Studio Code v.1.40.2;
  • Installation of C# (the Visual Studio Code extension);安装 C#(Visual Studio Code 扩展);
  • Installation of .Net; .Net的安装;
  • Setting up VS Code as Unity Script Editor (as described here );设置VS守则统一脚本编辑器(如描述这里);

At this point I imported my project root folder in the VS Code workspace but the IntelliSense function doesn't work.此时我在 VS Code 工作区中导入了我的项目根文件夹,但 IntelliSense 功能不起作用。 So I read this guide and then I ran:所以我阅读了本指南,然后我跑了:

dotnet new console
dotnet run

Now it seems that the IntelliSense works but VS Code doesn't recognize the Unity classes and, for this reason, my project is full of errors.现在看来 IntelliSense 可以工作,但 VS Code 无法识别 Unity 类,因此,我的项目充满了错误。 Is there a way to fix it or to import the UnityEngine package?有没有办法修复它或导入 UnityEngine 包?

You don't need .Net for working with Unity projects.您不需要 .Net 来处理 Unity 项目。 Just install Microsoft .Net Framework 4.7.1 SDK to make your C# Omnisharp VS Code extension work properly.只需安装 Microsoft .Net Framework 4.7.1 SDK 即可使您的 C# Omnisharp VS Code 扩展正常工作。 Nothing else should be done, just open your project and everything should be OK.什么都不应该做,只需打开您的项目,一切都应该没问题。

See your VS Code OUTPUT->Omnisharp Log, it'll ask you to install .Net Framework SDK查看你的 VS Code OUTPUT->Omnisharp Log,它会要求你安装 .Net Framework SDK

Also, you need to open your project with Unity Editor at least once, otherwise you'll get a lot of 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) and so on erros in your VS Code even for a workable project.另外,你需要至少用Unity Editor打开你的项目一次,否则你会得到很多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)等错误,即使对于可行的项目也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM