I have a GUI.Box that is a selection box for units in my RTS game. Im wondering how to use GUI.depth to change the depth of this box so that it goes behind my other gui elements. I’ve tried setting the depth to positive and negative values but its not working going behind my other gui elements that are on the default sorting layer at depth 0 on the Canvas component. Please tell me what Im doing wrong. Thanks
void OnGUI()
{
if (UserIsDragging) {
boxWidth = Camera.main.WorldToScreenPoint (MouseDownPoint).x - Camera.main.WorldToScreenPoint (currentMousePoint).x;
boxheight = Camera.main.WorldToScreenPoint (MouseDownPoint).y - Camera.main.WorldToScreenPoint (currentMousePoint).y;
boxLeft = Input.mousePosition.x;
boxTop = (Screen.height - Input.mousePosition.y) - boxheight;
GUI.Box (new Rect (boxLeft, boxTop, boxWidth, boxheight), "", MouseDragSkin);
GUI.depth = 1;
}
}
}