In the production of the NPC car's route, put point----and put into the array--draw line, each point into the array is a waste of time, so I consider to put all the points in a parent, in order to Edito mode, the dynamic acquisition of all point information, and then draw the route.
I use the Enable state of the script to control the acquisition of array elements.
1 usingUnityengine;2 usingSystem.Collections;3 4 /// <summary>5 ///Custom Draw Route tool:6 ///ParentObject: Father object of the route point, need to assign the route of the Hierachy panel to ParentObject7 ///pointcounts: Number of route points8 ///childobjects: Storing father downlevel subset of Road point object Set9 /// </summary>Ten [Executeineditmode] One Public classDrawroadline:monobehaviour { A PublicGameobject ParentObject; - Public intpointcounts; - Publicgameobject[] childobjects; the //initializing the script state - voidAwake () - { - This. Enabled =false; + } - //activating state Dynamic read Route point + voidonenable () A { atPointcounts = Parentobject.getcomponentsinchildren<transform> (). Length-1; -Childobjects =Newgameobject[pointcounts]; - stringPath =Parentobject.name; - Debug.Log (path); - for(inti =0; i < pointcounts; i++) - { inChildobjects[i] = gameobject.find (path +"/point_"+i); - } to + } - //draw a closed route the voidOndrawgizmos () * { $ if(Pointcounts <=0)Panax Notoginseng return; -Gizmos.color =Color.yellow; the for(inti =0; i < pointcounts; i++) + { A if(I < pointcounts-1) the { +Gizmos.drawline (childobjects[i].transform.position, Childobjects[i +1].transform.position); - } $ Else $ { -Gizmos.drawline (Childobjects[i].transform.position, childobjects[0].transform.position); - Break; the } - }Wuyi } the - Wu}
Unity Route Drawing Tool