Help! Unsaved work stuck in frozen unity, believed to be from infinite loop. What can i do?

I used this code as i wanted to only move one way at a time to stick strictly to two axis but i believe i created an infinite loop from looking at Can the Unity editor break out of an infinite loop in a script? - Questions & Answers - Unity Discussions, the question seemed to solve my problem but as i have the latest version of unity i now use visual studio not mono-develop so i am quite stuck. I will display my code so that you can maybe spot how to avoid an infinite loop while keeping the desired functionality.

using UnityEngine;
using System.Collections;

public class Swivel : MonoBehaviour {
    public int speed;
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {
        int blah = 1;
        while (blah == 1)
            if (Input.GetKey(KeyCode.LeftArrow))
                transform.Rotate(Vector3.up * Time.deltaTime * speed);

            if (Input.GetKey(KeyCode.RightArrow))
                transform.Rotate(Vector3.down * Time.deltaTime * speed);

            if (Input.GetKey(KeyCode.UpArrow))
                transform.Rotate(Vector3.left * Time.deltaTime * speed);

            if (Input.GetKey(KeyCode.DownArrow))
                transform.Rotate(Vector3.right * Time.deltaTime * speed);

Visual studio is still working but i just need help to protect my unsaved work through the same technique as

I know it’s an old question but I do
have a better solution.
As others have said: don’t use an
infinite loop by design. However if
you did it by mistake and don’t want
to loose a whole scene or other
unsaved data here’s what you can do:

  1. Open mono develop and attach it to
    the editor if you haven’t already.(Run

Attach To Process)

  1. Pause execution from mono
    develop.(Run > Pause)

  2. Go to your immediate window (View >
    Debug Windows, if you don’t see it at
    the bottom).

  3. Modify the value that’s causing you
    to loop infinitely. The Immediate
    window lets you just type in some code
    that will execute in that scope.

For me, the problem was looping over a
list and trying to find a specific
value that matched an element. I
didn’t properly handle the value not
existing so it looped infinitely. All
I had to do was call listname.Clear();
in the immediate window and the loop
broke out on the next iteration.

If you were doing something
exceptionally silly like while(true){
/ some silly code / } you might be
able to break out by just calling
return. If you were calling that
function every frame you might have to
be a bit more sneaky and call
or something to that effect to remove
the script that’s calling that silly

I hope this helps someone else who
doesn’t want to nuke their work in


Thank you for reading this and if you can help please help sooner rather than later as I am eager to finish off my work. Thanks!

The time-honored, mostly official answer is: Save your work. You have to lose unsaved work several times before you learn to Save, make backups … and this is one of those times.

A real project involves redoing and rewriting the same code over and over and over as insane managers come and go, testers hate what you have now … . Having to redo a few days of lost work (which won’t take nearly as long the second time) is good practice for this.

this video explains in pretty good depth exactly what to do if your unity completely freezes from a loop and you use visual studio