Real machine debugging, sometimes need to quickly add some debugging information on the screen, such as the character's collision box, the crosshair range, can be used GL on the screen to draw a rectangular circle, etc. to display:
Start Drawing:
void Begin (color color) { ifnull) new Material (Shader.find (" unlit/color")); S_material. SetPass (0); Gl. Loadortho (); Gl. Begin (GL. LINES); S_material. SetColor ("_color", Color);}
End Drawing:
void End () { GL. End ();}
To draw a rectangle:
Public voiddrawscreenrect (rect rect, color color) {Begin (color); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymin/screen.height,0); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymax/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymin/screen.height,0); Gl. Vertex3 (Rect.xmax/Screen.width, Rect.ymin/screen.height,0); Gl. Vertex3 (Rect.xmin/Screen.width, Rect.ymin/screen.height,0); End ();}
To draw an ellipse:
Public voidDrawscreenellipse (Vector2 Center,floatXradius,floatYradius, color color,intSmooth = -) {Begin (color); for(inti =0; i < smooth; ++i) {intNextStep = (i +1) %Smooth; Gl. Vertex3 ((center.x+ Xradius * Mathf.cos (2* Mathf.pi/smooth * i)/Screen.width, (Center.y+ Yradius * Mathf.sin (2* Mathf.pi/smooth * i))/Screen.height,0); Gl. Vertex3 ((center.x+ Xradius * Mathf.cos (2* Mathf.pi/smooth * nextStep))/Screen.width, (Center.y+ Yradius * Mathf.sin (2* Mathf.pi/smooth * nextStep))/Screen.height,0); } End ();}
Unity draws lines with GL Library