- Home /
Rect with a height of 0 has a non-zero height
I'm drawing a box on the gui with this function:
void DrawQuad(Rect position, Color color) {
texture.SetPixel(0,0,color);
texture.Apply();
GUI.skin.box.normal.background = texture;
GUI.Box(position, GUIContent.none);
}
When I call it with DrawQuad(new Rect(10f, Screen.height - 48f, 10f, 0f), ColorPalette._yellow);
It draws a square like this:
Note that the Rect's height is 0.
Through trial and error the thinnest I can get it is when I put the height to around 5.8f, but even then it's not super thin:
Why is the flattest box only when I put the Rect height at 5.8 (instead of 0)? This is pretty counterintuitive. Is there any way to make the box 1 pixel high? (essentially a line)
Answer by Bunny83 · Dec 24, 2017 at 12:54 PM
You use the default box style. It has some margin, padding as well as a border. The border is most likely your problem. When you use a rect with height 0 the border will actually overlap on the wrong side.
You may want to have a look at my IMGUI crash course as well as the official documentation
Your answer
Follow this Question
Related Questions
Start of level Dialogue 2 Answers
Button then instanitates gameobject 1 Answer
FirstPerson and Audioplay??? 1 Answer
How do Text Fields work? (Backend) 1 Answer