- Home /
draw a box with transparent background (outline)
I am trying to draw an outline (a transparent box with colored border essentially)
I have the following code adapted from here
void OnGUI(){
GUI.Box (new Rect (10,10,200,30), "Object", InitStyles(new Color( 0f, 0f, 0f, 0.0f )));
}
private GUIStyle InitStyles(Color color){
GUIStyle currentStyle = null;
if( currentStyle == null ){
currentStyle = new GUIStyle (GUI.skin.box );
currentStyle.normal.background = MakeTex( 2, 2, color );
}
return currentStyle;
}
private Texture2D MakeTex( int width, int height, Color col ){
Color[] pix = new Color[width * height];
for( int i = 0; i < pix.Length; ++i ){
pix[ i ] = col;
}
Texture2D result = new Texture2D( width, height );
result.SetPixels( pix );
result.Apply();
return result;
}
This is getting rid of the border along with the background color.
Is there a better way to do this?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612150540im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to create GUIBox with tools? 0 Answers
Adding white border to boxes 0 Answers
Fading between scenes 1 Answer
Moving rectangles to the edge of the screen to make borders 3 Answers