我在 Unity 中构建了一个自定义金字塔,如下所示:
Mesh mesh = GetComponent<MeshFilter>().mesh;
mesh.Clear();
Vector3[] vertices = {
new Vector3(0.0f, 0.5f, 0.0f),
new Vector3(0.5f, 0.0f, 0.5f),
new Vector3(-0.5f, 0.0f, 0.5f),
new Vector3(-0.5f, 0.0f, -0.5f),
new Vector3(0.5f, 0.0f, -0.5f),
};
int[] triangles = {
1, 2, 3,
1, 3, 4,
1, 0, 2,
2, 0, 3,
3, 0, 4,
4, 0, 1
};
mesh.vertices = vertices;
mesh.triangles = triangles;
我正在尝试为我的金字塔着色,正如统一文档中所述:
Color[] colors = new Color[vertices.Length];
for (int i = 0; i < vertices.Length; i++)
colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].y);
// assign the array of colors to the Mesh.
mesh.colors = colors;
但这不会改变什么..
我的对象没有任何材料,只有这个脚本。
有任何想法吗?