Unity Scripts edited in Visual studio don't provide autocomplete

前端 未结 26 1486
半阙折子戏
半阙折子戏 2020-11-22 10:02

When I want to edit C# Unity scripts, they open in Visual Studio. It is supposed to provide auto complete for all Unity related code, but it doesn\'t work.

Here you c

相关标签:
26条回答
  • 2020-11-22 10:08

    one of the above methods are worked for me and I just found a solution to this problem,
    1. First, go to the project directory and delete .sln file
    2. Second, go to unity and double click your script. Then Visual Studio will be open with an error,

    1. Then click ok and close Visual Studio editor.
    2. Finally, turn off your Windows Defender and then go to your project directory and there will be .csproj file. Just double click and open this from your Visual Studio editor and open the scripts folder inside the assets folder and open the scripts and autocompletion will be working perfectly fine.
    0 讨论(0)
  • 2020-11-22 10:09

    Two Alternative Options:

    Fix 1

    @singleton pointed me in this direction. Instead of changing the target in Visual Studio you should change it in Unity since the project is auto-generated.

    First delete the auto generated Visual Studio files: .csproj .user .sln

    Then from within Unity go to PlayerSettings and under 'Other Settings' change the 'Scripting Runtime Version' from Stable 3.5 to Experimental 4.6.

    However, that didn't fix it for me.

    Fix 2

    I noticed all of the references to Unity related code was marked with a yellow warning. Check your error logs and see if this is the case. In particular see if you get the following error: getreferenceNearestTargetframeworkTask

    If so try: Start Visual Studio Installer again.

    On the Build Tools 2017, click Modify,

    Ensure that "Nuget targets and build tasks" are ticked. This should become ticked if you click on Universal Windows Platform development.

    0 讨论(0)
  • My autocomplete also didn't work because Visual Studio Tools for Unity wasn't installed. So, after you install that, delete the auto generated Visual Studio files. Others said that you open file again and the problem is solved but it's not.

    The trick is: instead of normally double-clicking the file, you need to open the C# file from Unity by right click and then "Open C# Project".

    0 讨论(0)
  • 2020-11-22 10:11

    Unload and reload the project, in Visual Studio:

    • right click your project in Solution Explorer
    • select Unload Project
    • select Reload Project

    Fixed!

    I found this solution to work the best (easiest), having run into the problem multiple times.

    Source: https://alexdunn.org/2017/04/26/xamarin-tips-fixing-the-highlighting-drop-in-your-xamarin-android-projects/

    0 讨论(0)
  • 2020-11-22 10:11

    Update 2020 with Visual Studio Community 2019 and Unity 2019.3:

    1. Open Visual Studio Installer as Administrator, select to modify your current installation and add "Game development for Unity"

    2. If you add a new c# script in Unity now, and open it (automatically) with Visual Studio, it is not described as "Miscellaneous" at the top of the window but with "Assembly-CSharp", and the autocomplete works.

    0 讨论(0)
  • 2020-11-22 10:13

    What worked me is that I copied all the code inside the broken class and removed that file. Then, I opened an empty file and pasted.

    Result: beautiful syntax highlights came back!

    0 讨论(0)
提交回复
热议问题