Hi,
I need help with a small problem. I’d like to have a GUI element (in this case a window) that is draggable along the x-axis. I did it like this:
using UnityEngine;
using System.Collections;
public class DragTest : MonoBehaviour {
public float yPosition = 0.0f;
private Rect windowRect = new Rect (0, Screen.height/2 - 50, 100, 100);
void OnGUI () {
Event e = Event.current;
Rect windowRect = new Rect (yPosition, Screen.height/2 - 50, 100, 100);
windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
if (windowRect.Contains(Input.mousePosition) e.type == EventType.MouseDrag) {
yPosition = e.mousePosition.x;
}
}
void WindowFunction (int windowID) {
// Draw any Controls inside the window here
}
}
I can actually drag it from the left to the right, but not into the other direction. Why is that and how can I solve the problem?
Thx in advance!