There are at least three solutions (if there are others - let me know): two quick and one long. And what is long connected with Visual Studio (why can't Microsoft have it all simple?)
The fastest (but financially expensive)
You need to go to the UnityAssetStore and find an asset called Panic Button . It is located in the Editor Extensions / System section. At the moment, this asset is right here .
What is he doing? When the application is spinning in an infinite loop and the Unity interface is hanging, just press the Shift + Esc keys and the main thread "breaks", the interface hangs. At the same time, the playback is paused, and the problem location is displayed on the console:

How exactly does it work? What happens inside? Most likely, what will be described in paragraph 3, only made in the form of a script, packaged in a dll (so that no one can see the code), connected to the project.
Use MonoDevelop
The steps are as follows:
- We write a script with an infinite loop, hang it on the object and click
Play :-) Go to MonoDevelop and click Run → Attach To Process

In the window that appears, select Unity and click Attach

Push the Pause button in MonoDevelop

Mono will already stop in the problem area and StackTrace will be StackTrace

It now remains to put Breakpoint on the line, change the value that enters into an infinite loop (in this case, assign i a value of 20, for example) and click Continue Execution

To sigh with a relief.
Use Visual Studio
Steps:
We write a script with an infinite loop, hang it on the object and click Play :-)
For example, the script is:
using UnityEngine; public class Quicksand : MonoBehaviour { void OnMouseDown() { while(true) { // "Mind you, you'll keep sinking forever!!", -- My mom } } }
Go to Visual Studio , click on the menu Debug → Attach to Process and select Unity in the process list.
Note (!) : It Attach to Process , NOT Attach To Unity

Next, click Debug → Break all to stop the process.
It is necessary to find the disassembled view (if it does not automatically appear). In theory, on the StackTrace tab, if you double-click the LMB , a window will appear in which you can click the view disassembly link

And through the stack to get to the hang. The animation below should fully show how to get there:

As a result, we get about the following picture:

It almost shows an endless loop.
In reality, the code can be more difficult and it will be difficult to quickly figure out what is happening there, but you can not go into much, because there is a small trick (see the next step):
F10 - take a step in debugging without going into a function / method. Accordingly, now step by step we press F10 until we fly from line 000000001015A758 jmp 000000001015A743 to the line with the instruction cmp dword ptr [r11], 0 .

As a result, these values should appear in the Autos tab in Visual Studio :

Now just change the value of the "variable" R11 to zero (0)

Since we are standing at the cmp address, when attempting to execute the instruction, it will try to read address 0, which, in turn, will generate an error. What we do: Press F5 (continue program execution), and then select Continue in the pop-up window.

In theory, Unity should come to life and spit a mistake into the console, indicating where the catch was:

To sigh with a relief.
PS The way with Visual Studio was borrowed in the Unity blog . There you can read why the method works 
break all, which also has to stop at the point of hangup .... but even that is not so simple, it seems there ......... in the end, through the mono it grabbed? and the fact that the blog is written in the first link did not try? - Alexey Shimansky