Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetPositions

Set the positions of all vertices in the line.
Read time 4 minutesLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

SetPositions(Vector3[])

Set the positions of all vertices in the line.
public void SetPositions(Vector3[] positions)

Parameters

positions

The array of positions to set.

Remarks

This method is preferred to LineRenderer.SetPosition when setting all positions, as it is more efficient to set all positions using a single command than to set each position individually. Note that LineRenderer.positionCount must be called before LineRenderer.SetPositions. Also LineRenderer.SetPositions ignores points with indices beyond LineRenderer.positionCount.
Additional Resources: LineRenderer.positionCount property, LineRenderer.SetPosition function.

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ // Creates a line renderer that follows a Sin() function // and animates it. public Color c1 = Color.yellow; public Color c2 = Color.red; public int lengthOfLineRenderer = 20; LineRenderer lineRenderer; void Start() { lineRenderer = gameObject.AddComponent<LineRenderer>(); lineRenderer.material = new Material(Shader.Find("Sprites/Default")); lineRenderer.widthMultiplier = 0.2f; lineRenderer.positionCount = lengthOfLineRenderer; // A simple 2 color gradient with a fixed alpha of 1.0f. float alpha = 1.0f; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) } ); lineRenderer.colorGradient = gradient; } void Update() { LineRenderer lineRenderer = GetComponent<LineRenderer>(); var points = new Vector3[lengthOfLineRenderer]; var t = Time.time; for (int i = 0; i < lengthOfLineRenderer; i++) { points[i] = new Vector3(i * 0.5f, Mathf.Sin(i + t), 0.0f); } lineRenderer.SetPositions(points); }}

SetPositions(NativeArray<Vector3>)

Set the positions of all vertices in the line.
public void SetPositions(NativeArray<Vector3> positions)

Parameters

The array of positions to set.

Remarks

This method is preferred to LineRenderer.SetPosition when setting all positions, as it is more efficient to set all positions using a single command than to set each position individually. Note that LineRenderer.positionCount must be called before LineRenderer.SetPositions. Also LineRenderer.SetPositions ignores points with indices beyond LineRenderer.positionCount.
Additional Resources: LineRenderer.positionCount property, LineRenderer.SetPosition function.

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ // Creates a line renderer that follows a Sin() function // and animates it. public Color c1 = Color.yellow; public Color c2 = Color.red; public int lengthOfLineRenderer = 20; LineRenderer lineRenderer; void Start() { lineRenderer = gameObject.AddComponent<LineRenderer>(); lineRenderer.material = new Material(Shader.Find("Sprites/Default")); lineRenderer.widthMultiplier = 0.2f; lineRenderer.positionCount = lengthOfLineRenderer; // A simple 2 color gradient with a fixed alpha of 1.0f. float alpha = 1.0f; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) } ); lineRenderer.colorGradient = gradient; } void Update() { LineRenderer lineRenderer = GetComponent<LineRenderer>(); var points = new Vector3[lengthOfLineRenderer]; var t = Time.time; for (int i = 0; i < lengthOfLineRenderer; i++) { points[i] = new Vector3(i * 0.5f, Mathf.Sin(i + t), 0.0f); } lineRenderer.SetPositions(points); }}

SetPositions(NativeSlice<Vector3>)

Set the positions of all vertices in the line.
public void SetPositions(NativeSlice<Vector3> positions)

Parameters

The array of positions to set.

Remarks

This method is preferred to LineRenderer.SetPosition when setting all positions, as it is more efficient to set all positions using a single command than to set each position individually. Note that LineRenderer.positionCount must be called before LineRenderer.SetPositions. Also LineRenderer.SetPositions ignores points with indices beyond LineRenderer.positionCount.
Additional Resources: LineRenderer.positionCount property, LineRenderer.SetPosition function.

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ // Creates a line renderer that follows a Sin() function // and animates it. public Color c1 = Color.yellow; public Color c2 = Color.red; public int lengthOfLineRenderer = 20; LineRenderer lineRenderer; void Start() { lineRenderer = gameObject.AddComponent<LineRenderer>(); lineRenderer.material = new Material(Shader.Find("Sprites/Default")); lineRenderer.widthMultiplier = 0.2f; lineRenderer.positionCount = lengthOfLineRenderer; // A simple 2 color gradient with a fixed alpha of 1.0f. float alpha = 1.0f; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) } ); lineRenderer.colorGradient = gradient; } void Update() { LineRenderer lineRenderer = GetComponent<LineRenderer>(); var points = new Vector3[lengthOfLineRenderer]; var t = Time.time; for (int i = 0; i < lengthOfLineRenderer; i++) { points[i] = new Vector3(i * 0.5f, Mathf.Sin(i + t), 0.0f); } lineRenderer.SetPositions(points); }}