答案 0 :(得分:4)
您可以使用MeshTopology.Lines或MeshTopology.LineStrip
直接从文档中获取:
...在某些情况下,您可能希望渲染由线或点组成的复杂事物。使用这种拓扑创建网格并使用它进行渲染通常是最有效的方法。
下面是创建线带网格的脚本。只需将其放在一个空的GameObject上。
网格看起来像这样:
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class LineStrip : MonoBehaviour {
void Start() {
GetComponent<MeshRenderer>().material = new Material(Shader.Find("Sprites/Default"));
int n = 512;
Vector3[] verts = new Vector3[n];
Color[] colors = new Color[n];
int[] indices = new int[n];
for (int i = 0; i < n; i++)
{
// Indices in the verts array. First two indices form a line,
// and then each new index connects a new vertex to the existing line strip
indices[i] = i;
// Vertex colors
colors [i] = Color.HSVToRGB( (float)i/n, 1, 1 );
// Vertex positions
verts[i] = new Vector3( i / 64f, Mathf.Sin( i/32f ), 0);
}
Mesh m = new Mesh
{
vertices = verts,
colors = colors
};
m.SetIndices(indices, MeshTopology.LineStrip, 0, true);
GetComponent<MeshFilter>().mesh = m;
}
}