public Color[] colors ;

Description

网格的顶点颜色。

如果没有顶点颜色可用,则返回空数组。

// Sets the vertex color to be red at the y=0 and green at y=1.
// (Note that most built-in Shaders don't display vertex colors. Use one that does, such as a Particle Shader, to see vertex colors)

using UnityEngine;

public class ExampleClass : MonoBehaviour { void Start() { Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices;

// create new colors array where the colors will be created. 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; } }

出于性能原因,请考虑改用 colors32。这会避免颜色中的 字节到浮点数转换,并使用较少的临时内存。