- Home /
Question by
Benajben · Mar 17, 2014 at 11:53 PM ·
line drawing
Drawing a rectangle using OnGUI()
I'm trying to draw a rectangle with a clear fill, but im having some issues. I've managed to draw a filled rectangle with the following code
Texture2D rectTexture = null;
GUIStyle rectStyle = null;
//Note that this function is only meant to be called from OnGUI() functions.
void GUIDrawRect(Rect position, Color color)
{
if(rectTexture == null)
rectTexture = new Texture2D(1, 1);
if(rectStyle == null)
rectStyle = new GUIStyle();
rectTexture.SetPixel(0, 0, color);
rectTexture.Apply();
rectStyle.normal.background = rectTexture;
GUI.Box(position, GUIContent.none, rectStyle);
}
But I really need the middle of the rectangle not filled. I tried drawing a 2nd rectangle of Color.clear, but that didn't work (I didn't expect it to). If anyone has any insight on this that would be great.
Comment