usingUnityengine;usingSystem.Collections; Public classjoint{ PublicVector3 org; PublicVector3 end;} Public classexample:monobehaviour{Event E; PrivateVector3 Orgpos; PrivateVector3 Endpos; Private BOOLCandrawlines =false; ArrayList posal; ArrayList Temppos; PublicMaterial linematerial; voidStart () {Temppos=NewArrayList (); Posal=NewArrayList (); } voidUpdate () {if(Input.getmousebutton (0) ) {Candrawlines=true; } if(E.type! =NULL&candrawlines) { if(E.type = =eventtype.mousedown) {Orgpos=input.mouseposition; Endpos=input.mouseposition; } if(E.type = =Eventtype.mousedrag) {Endpos=input.mouseposition; //storing mouse position information in an arrayTemppos. ADD (input.mouseposition); Gldrawline (Orgpos, endpos); Orgpos=input.mouseposition; Print (Temppos. Count); } if(E.type = =eventtype.mouseup) {//orgpos=input.mouseposition; Endpos =input.mouseposition; } } } voidGldrawline (Vector3 Beg, Vector3 end) {if(!candrawlines)return; Gl. Pushmatrix (); Gl. Loadortho (); beg.x= beg.x/Screen.width; End.X= End.X/Screen.width; Beg.y= BEG.Y/Screen.height; End.y= END.Y/Screen.height; Joint Tmpjoint=NewJoint (); Tmpjoint.org=Beg; Tmpjoint.end=end; Posal.add (Tmpjoint); Linematerial.setpass (0); Gl. Begin (GL. LINES); Gl. Color (NewColor (1,1,1,0.5f)); for(intI=0; i<posal.count; i++) {Joint TJ=(joint) posal [i]; Vector3 Tmpbeg=tj.org; Vector3 Tmpend=Tj.end; Gl. Vertex3 (tmpbeg.x, Tmpbeg.y, tmpbeg.z); Gl. Vertex3 (Tmpend.x, Tmpend.y, tmpend.z); } GL. End (); Gl. Popmatrix (); } voidOngui () {e=event.current; if(GUI. Button (NewRect ( Max,0, -, -),"End Lines") ) {clearlines (); } } voidClearlines () {Candrawlines=false; Posal.clear (); } voidOnpostrender () {gldrawline (Orgpos, endpos); } }
GL Example 1