- Home /
GUI.DragWindow() dont work in C# (Unity 4.2), Java works?
Hey Everybody.
I build a simplyfied example of the problem. I am using Unity 4.2 on Windows7 x64.
If I program a samplecode in JS with a dragable window it works fine:
var windowRect : Rect = Rect (20, 20, 165, 50);
function OnGUI () {
windowRect = GUI.Window (100, windowRect, DoMyWindow, "TESTWINDOW JavaScript - movable");
}
function DoMyWindow (windowID : int) {
GUI.DragWindow (Rect (0, 0, 300, 50));
}
If I build a similar code for C# the window is NOT dragable. I read the documentation for it and searched the ANSWERS and forums about that without success... whats the problem?
using UnityEngine;
using System.Collections;
public class testwindow : MonoBehaviour {
Rect windowRect = new Rect(10, 100, 200, 100);
void OnGUI() {
GUI.Window(101, windowRect, windowDo, "TESTWINDOW c# - movable");
}
void windowDo(int windowID) {
// dont work????
GUI.DragWindow(new Rect(0, 0, 200, 100));
}
}
Answer by Jamora · Aug 08, 2013 at 10:38 AM
You are not assigning the return rect in your C# code.
It should say
windowRect = GUI.Window(101, windowRect, windowDo, "TESTWINDOW c# - movable");
like it does in yoru UnityScript code.
Hi.
I dont need the returncode. I cannot imagine this could be the error. Will check that later.
Answer by nenorse · Jan 29, 2014 at 06:38 PM
Jamora is correct. If you do not assign the returning Rect back from the method (which in turn is changed by your windowDo method) - then the Window will not Drag.