Search code examples
unity-game-enginelinepoints

How to create a line using two Vector3 points in unity?


I know there exist some functions like lineRenderer etc, but I want to create a straight line in the scene using two points(in Vector3 form). I don't want to draw the line by using any key or using the mouse, I just want to see the line in the scene when I trigger some event or just after I click play button.

Can anyone help me?


Solution

  • Ok, I've figured it out by using LineRenderer like this:

    var line: GameObject=GameObject.Find("/LineRenderer");
    fence = Instantiate(line,Pos,Rotation);
    fence.setPosition(0,p1);
    fence.setPosition(1,p2);
    

    Thanks for all of your answers above