Let’s begin with a video about this topic
In this article we see how to solve the Visual Studio error in which it does not autocomplete code, that is to say, it does not recognize the engine’s own components such as the GameObject, Component or RigidBody class, this makes the programming task very hard.
How to connect Visual Studio to Unity to make autocomplete work
First make sure that Visual Studio is installed, if this was not done at the time of installing Unity, you can install it by going to Unity HUB, to the “Installs” section and adding the Visual Studio module to the version of the engine you are using.
If Visual Studio is installed but still does not suggest us code we have to make sure that Visual Studio is connected to Unity, for that in Unity we go to Edit > Preferences > External Tools. In the Script editor part, using the drop-down menu choose “Visual Studio” (if this option does not appear it may indicate that Visual Studio is not installed), you can also use the “Browse” option to locate the executable of the editor you want to use.
Once this is done Visual Studio will start autocompleting code related to the Unity engine, such as GameObject, Collider or RigidBody components.