Unity Route Drawing Tool

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.