- Home /
line render from object to object
hey, how do i use a line renderer to make a line that can be seen in game that goes from one empty gameobject to another?
Answer by Jessy · Feb 18, 2011 at 12:03 PM
This code doesn't require the Game Objects to be empty, but that's fine. They just need Transform components, and you can't have a Game Object without one!
// Populate this array in the order you want the line to travel. var transforms : Transform[]; private var lineRenderer : LineRenderer;
function Awake () { lineRenderer = GetComponent.<LineRenderer>();
// Use this line again later, if transforms.Length changes.
lineRenderer.SetVertexCount(transforms.Length);
}
function Update () { for(var i = 0; i < transforms.Length; ++i) lineRenderer.SetPosition(i, transforms[i].position); }
Keep in mind, the Line Renderer doesn't actually make lines. I recommend Vectrosity for that.
Your answer
Follow this Question
Related Questions
Dynamically fill color in a gameobject? 1 Answer
Game object with animations 0 Answers
line renderer question 1 Answer
Renderer.enable for GameObject[]? 3 Answers
GameObject doesn't turn on when renderer camera is visible. 2 Answers