- Home /
Debug.draw rect
how can I draw with gizmo a rect? this is my code but it sure is wrong because it takes as parameters the Vector3
function Start(){
Debug.DrawLine(Rect(10,10,100,100), Color.green);
}
Answer by robertbu · Jul 17, 2013 at 09:58 AM
From the values, I'm assuming the Rect is in GUI coordinates. If so, drawing a wireframe rectangle is not simple. Debug.DrawLine() or Gizmos.DrawLine() (which is probably more what you want), use World coordinates, so you would need to calculate and translate all four corners of the rectangle from GUI to coordinates and then draw individual lines between the corners to frame the rectangle. If you are just looking to visualize a rectangle, then this might be what you are looking for:
If your texture used in this function is a frame, then you would get an outline of the rectangle.
Answer by elioneimi · May 06, 2021 at 09:54 AM
var rect = new Rect(0f, 0f, 100f, 100f);
Debug.DrawLine(new Vector3(rect.x, rect.y), new Vector3(rect.x + rect.width, rect.y ),Color.green);
Debug.DrawLine(new Vector3(rect.x, rect.y), new Vector3(rect.x , rect.y + rect.height), Color.red);
Debug.DrawLine(new Vector3(rect.x + rect.width, rect.y + rect.height), new Vector3(rect.x + rect.width, rect.y), Color.green);
Debug.DrawLine(new Vector3(rect.x + rect.width, rect.y + rect.height), new Vector3(rect.x, rect.y + rect.height), Color.red);