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.SetPosition

Switch to Manual
public void SetPosition(int index, Vector3 position);

Parameters

Description

Set the position of the vertex in the line.

See Also: SetVertexCount function.

See Also: SetPositions function.

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>(); float t = Time.time; int i = 0; while (i < lengthOfLineRenderer) { Vector3 pos = new Vector3(i * 0.5F, Mathf.Sin(i + t), 0); lineRenderer.SetPosition(i, pos); i++; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961