Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

SetVertexCount(count: int): void;
void SetVertexCount(int count);
def SetVertexCount(count as int) as void

Description

Set the number of line segments.

See Also: SetPosition function.

	// Creates a line renderer that follos 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); for(var i : int = 0; i < lengthOfLineRenderer; i++) { var pos : Vector3 = Vector3(i * 0.5, Mathf.Sin(i + Time.time), 0); lineRenderer.SetPosition(i, pos); } }

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>();
        int i = 0;
        while (i < lengthOfLineRenderer) {
            Vector3 pos = new Vector3(i * 0.5F, Mathf.Sin(i + Time.time), 0);
            lineRenderer.SetPosition(i, pos);
            i++;
        }
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public c1 as Color = Color.yellow

	public c2 as Color = Color.red

	public lengthOfLineRenderer as int = 20

	def Start() as void:
		lineRenderer as LineRenderer = gameObject.AddComponent[of LineRenderer]()
		lineRenderer.material = Material(Shader.Find('Particles/Additive'))
		lineRenderer.SetColors(c1, c2)
		lineRenderer.SetWidth(0.2F, 0.2F)
		lineRenderer.SetVertexCount(lengthOfLineRenderer)

	def Update() as void:
		lineRenderer as LineRenderer = GetComponent[of LineRenderer]()
		i as int = 0
		while i < lengthOfLineRenderer:
			pos as Vector3 = Vector3((i * 0.5F), Mathf.Sin((i + Time.time)), 0)
			lineRenderer.SetPosition(i, pos)
			i++