Code Snippet – Draw Debug Rectangle in Unity3D

April 13, 2015 6:42 am Veröffentlicht von Schreibe einen Kommentar

Not too many words to this. I was searching for quick solution to draw a debug rectangle (ok many rectangles for pathfinding debugging) in Unity3D and found nothing on the internet.

Its as easy as follows:

void DebugDrawColoredRectangle(Vector3 position, float size, Color color)
{
Debug.DrawLine(position, new Vector3(position.x + size, position.y, position.z), color);
Debug.DrawLine(position, new Vector3(position.x, position.y – size, position.z), color);
Debug.DrawLine(new Vector3(position.x, position.y – size, position.z), new Vector3(position.x + size, position.y – size, position.z), color);
Debug.DrawLine(new Vector3(position.x + size, position.y – size, position.z), new Vector3(position.x + size, position.y, position.z), color);
}

 

Just copy and paste this code and call it with

this.DebugDrawColoredRectangle(Vector3.zero, 1, Color.red);

 

Thats it. Hope it helps someone to save time.

Kategorisiert in:

Dieser Artikel wurde verfasst von Chris

Schreib einen Kommentar