public static void DrawRect(this Bounds bounds, Color color, float duration) { //USE: Overflow for DrawRect which accepts bounding box. Functions similarly to Debug.DrawLine except it draws a 2D rectangle (using given rect transform properties) //CREDIT: Created by Christian Hotte //Initializations: Rect rectangle = bounds.BoundsToRect(); //Convert given bounds to rectangle Vector2 topLeft = new Vector2(rectangle.xMin, rectangle.yMax); //Top left corner point Vector2 topRight = new Vector2(rectangle.xMax, rectangle.yMax); //Top right corner point Vector2 botRight = new Vector2(rectangle.xMax, rectangle.yMin); //Bottom right corner point Vector2 botLeft = new Vector2(rectangle.xMin, rectangle.yMin); //Bottom left corner point Vector2[] corners = { topLeft, topRight, botRight, botLeft }; //Place all four corners in array //Draw Sides: for (int x = 0; x < corners.Length; x++) //Parse through list of corners... { //Initialization: int nextCornerIndex = x + 1; if (nextCornerIndex >= corners.Length) { nextCornerIndex = 0; //Get index of corner after this corner } Vector2 corner1 = corners[x]; //Get primary corner location Vector2 corner2 = corners[nextCornerIndex]; //Get secondary corner location //Draw Side: Debug.DrawLine(corner1, corner2, color, duration); //Draw line between each two consecutive sides and in the specified color } }