Using VS Code as Unity’s code editor

portal

First download .NET, download address https://docs.microsoft.com/zh-cn/dotnet/core/install/ . Complete the download and installation of .NET for the corresponding platform. Remember to add environment variables for ease of use.
Then download and install MONO at: https://www.mono-project.com/download/stable/

Then install the extension in vs code:

The first extension [1] and the second extension [2] with strikethrough below do not need to be installed directly after 23 years. Just search and install the "Unity"
extension in VS Code . Even "Configuration Environment [3]" does not need to be configured. "Unity" will automatically install C# Dev Kit, C# and some other extensions. However, the problem with the current version of the extension is that it will automatically download .net again. The solution is:

Unity


Automatic download

Find the .NET Runtime Install Tool extension in the VS Code extension list ; click the gear in the lower right corner and select extension settings in the pop-up menu ; click Edit in settings.json on the opened settings page to open the settings.json file.
Or use other methods to open the settings.json file.
Add the following content at the end of the settings.json file:

"dotnetAcquisitionExtension.existingDotnetPath": [
    {
    
    
        "extensionId": "ms-dotnettools.csharp",
        "path": "你的dotnet程序路径"
    },
    {
    
    
        "extensionId": "ms-dotnettools.csdevkit", 
        "path": "你的dotnet程序路径"
    },
    {
    
    
        "extensionId": "visualstudiotoolsforunity.vstuc", 
        "path": "你的dotnet程序路径"
    }
]

Save and restart VS Code.
ok
The dotnet version is 7.0.

It is worth noting: Do not delete the Visual Studio Editor under Package Manager->Unity Registry, and ensure that the version is greater than or equal to 2.0.20.
Even if the editor you use is Visual Studio Code, do not delete it. Keep Visual Studio Editor and Visual Studio Code Editor, otherwise errors may be reported.


  1. c# programming support (c#)[1]
    c#-extension
  2. Unity Debugger Tool (Debugger for Unity) [2]
    Debugger for Unity
    How to use this debugging tool, please use VS Code as Unity's code editor .

  1. Unity code prompts (Unity Snippets)
    Unity Snippets
    use this tool to prompt you about Unity's life cycle methods, Unity classes, etc.

  2. c# code color (eppz!) [Optional]
    code color
    Change the code color so that classes and types have unique colors, as follows:
    example
    If you want to use this extension, you need to manually set a color theme on its extension details page.
    Set color theme

Configure environment[3]

Set "omnisharp.monoPath": "mono installation path" and "omnisharp.useGlobalMono": "always" in the settings of vs code .

The new version no longer has the useGlobalMono option, and the configuration is slightly different.
Remove the √ of Omnisharp.UseModernNet
and then set Omnisharp.MonoPath to your path. If you
don’t know the path, you can enter it in the terminal dotnet --infoor dotnet --list-sdksview it (provided you have configured environment variables).
You must ensure that the two-level directory at the end is "version number/Current" "

Insert image description hereInsert image description here

The c# script can see the code prompt indicating that the configuration is complete. If it doesn't work, you can check the output console to check the error message, and correct it according to the error message.

Guess you like

Origin blog.csdn.net/weixin_45345384/article/details/120581065