Search Unity

Draw a rectangle with borders

Discussion in 'Immediate Mode GUI (IMGUI)' started by ChrisX, Apr 16, 2015.

  1. ChrisX

    ChrisX

    Joined:
    Feb 13, 2015
    Posts:
    63
    Hello, everyone.

    I'm trying to tinker with drawing GUI in order to create a grid system and while I found out how to draw a rectangle, I want to know if there is something I can do to add a border to the edges of the rectangle. Like a red rectangle, but the edges are colored black.

    How do I do it?

    Extra question:

    This is my code, based on something dug on another topic:

    Code (CSharp):
    1. public static void GUIDrawRect( Rect position, Color color )
    2.     {
    3.         if( _staticRectTexture == null )
    4.         {
    5.             _staticRectTexture = new Texture2D( 1, 1 );
    6.         }
    7.        
    8.         if( _staticRectStyle == null )
    9.         {
    10.             _staticRectStyle = new GUIStyle();
    11.         }
    12.        
    13.         _staticRectTexture.SetPixel( 0, 0, color );
    14.         _staticRectTexture.Apply();
    15.        
    16.         _staticRectStyle.normal.background = _staticRectTexture;
    17.        
    18.         GUI.Box( position, GUIContent.none, _staticRectStyle );
    19.        
    20.        
    21.     }
    While this would draw the rectangle to the game screen, it's not on the Scene. How do I make it appear on Scene? Or is it impossible, or that the only way I can make grids/panels like that is to use a self-created object myself?
     
    unity_dP5kTjFeVFUDxQ likes this.