Moving GUI Elements

Hello, I’m trying to fake an OS inside of unity for a hacker simulation game. And I’m just trying to get windows to be drug around and resized. Not a fan of the GUI.Window, I gave it a try and it would not cooperate well with me. I found it much easier and achievable to modify the look and feel of my windows if I used groups and texture elements.

But I’m trying to get the object to move, and I thought that this would work:

 if (GUI.RepeatButton(new Rect(0, 0, xPositionButton, yPositionButton), "This is the move box"))
        {
            moveWindow = true;
        }

        while (moveWindow)
        {
            //Do Movement Code Here
            Debug.Log("Works");

            if(Input.GetButtonUp("Fire1"))
                moveWindow = false;
        }

And everytime I run the game to see if it works, Unity locks up. I’m imagining that I’m causing some type of memory error to occur. And I’m very open to different ways to accomplish what I’m trying to do, or if someone can tell me what the error is so that I can fix it. Thank you very much.

The problem here is the “while” loop. The reason Unity hangs is because the loop never exits, presumably because the Fire1 button is never released (are you sure this button is pressed in the first place?) However, it won’t give you the movement you want anyway. The results of the OnGUI function are only displayed after it exits. It gets called every frame so you need to move the object a short distance on each call. For example, if you are dragging with the mouse then move the dragged object to the mouse position on each OnGUI call, but just do it once, not in a loop.