Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

LineRenderer.SetPositions

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public function SetPositions(positions: Vector3[]): void;
public void SetPositions(Vector3[] positions);

Parameters

Description

Set the positions of all vertices in the line.

This method is preferred to SetPosition, as it is more efficient to set all positions using a single command than to set each position individually.

See Also: SetVertexCount function.

See Also: SetPosition function.

	// Creates a line renderer that follows a Sin() function
	// and animates it.

var c1 : Color = Color.yellow; var c2 : Color = Color.red; var lengthOfLineRenderer : int = 20;

function Start() { var lineRenderer : LineRenderer = gameObject.AddComponent.<LineRenderer>(); lineRenderer.material = new Material (Shader.Find("Particles/Additive")); lineRenderer.SetColors(c1, c2); lineRenderer.SetWidth(0.2,0.2); lineRenderer.SetVertexCount(lengthOfLineRenderer); }

function Update() { var lineRenderer : LineRenderer = GetComponent.<LineRenderer>(); var points = new Vector3[lengthOfLineRenderer]; var t = Time.time; for(var i : int = 0; i < lengthOfLineRenderer; i++) { points[i] = Vector3(i * 0.5, Mathf.Sin(i + t), 0); } lineRenderer.SetPositions(points); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Color c1 = Color.yellow; public Color c2 = Color.red; public int lengthOfLineRenderer = 20; void Start() { LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>(); lineRenderer.material = new Material(Shader.Find("Particles/Additive")); lineRenderer.SetColors(c1, c2); lineRenderer.SetWidth(0.2F, 0.2F); lineRenderer.SetVertexCount(lengthOfLineRenderer); } void Update() { LineRenderer lineRenderer = GetComponent<LineRenderer>(); Vector3[] points = new Vector3[lengthOfLineRenderer]; float t = Time.time; int i = 0; while (i < lengthOfLineRenderer) { points[i] = new Vector3(i * 0.5F, Mathf.Sin(i + t), 0); i++; } lineRenderer.SetPositions(points); } }