Debugging Unity Code in Visual Studio

  1. In Unity > Preferences > External Tools, set External Script Editor to Visual Studio (make sure the Editor Attaching option is checked

  2. In Visual Studio, set a breakpoint on the line where you want the debugger to stop.

  3. In Visual Studio, attach the code editor to the Unity Editor.

AttachToUnity

  1. In Unity, enter play mode.

For details, see the official documentation: https://docs.unity3d.com/cn/2019.4/Manual/ManagedCodeDebugging.html