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
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,
.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.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.
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".
Unload and reload the project, in Visual Studio:
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/
Update 2020 with Visual Studio Community 2019 and Unity 2019.3:
Open Visual Studio Installer as Administrator, select to modify your current installation and add "Game development for Unity"
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.
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!