Unity3d Navmeshagent Draw Line/draw path

Source: Internet
Author: User

I saw a guy in the group today asking how to draw a line when he asks the game view to find a way.

Just a few days ago wrote a search road, and I do not know how to draw a line in the way, so decided to help him, he also good study

In Baidu looked up a bit of information, direct Search road painting path, seek road painting line ...

I'm not a party, I just want to see how other people have come true.

The result is nothing to search!!  Then search directly Unity3d line ... It sure is a lot of information!!

Debug.drawline; Use this function to see only the lines of the drawing in screen, which are not visible in the game

So how are we going to draw floss in the game?

Baidu give me Answer: linerenderer (line renderer)

Then check the Holy code: http://game.ceeger.com/Script/LineRenderer/LineRenderer.html

How to use their own look, I'm not here to say more

OK, start tapping the code.

First we create an empty gameobject and then add the line Renderer component

property settings such as:

Material I'm just dragging it, it doesn't matter.

At this point we double-click the gameobject you just created to view it in the scene view.

We can see a line appeared, because of my material problem, I show here is the Oval!! How about the brain to mend the line?

The two coordinates that we set in the component are actually two points, 2.1 lines, and that's how the line is generated ... It sounds like crap.

OK, let's start knocking on the code, the component setup.

Set two variables

1      Public Transform line;//is the gameobject we just added. 2     Private Linerenderer _linerenderer;//Storage Gameobject linerenderer Components

Initialize the _linerenderer in the Start method

1     void  2    {3         _linerenderer = line. Getcomponent<linerenderer>(); 4     }


Finally we draw the line after the road search

1                 vector3[] _path = Nav.path.corners; // Storage Path 2                 _linerenderer.setvertexcount (_path. Length); // set Number of segments 3                  for (int0; i < _path. Length; i++)4                {5                     _linerenderer.setposition (i, _path[i]);   Set line segment vertex coordinates 6                 }

It's that simple, look at the code, see the manual I mentioned above first.

Since there is a lot of code in my project that has nothing to do with pathfinding, and the above code is simple, I won't post the complete code.

Here are the test results:

This article link: http://www.cnblogs.com/shenggege/p/4129405.html

Unity3d Navmeshagent Draw Line/draw path

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.