Legacy Documentation: Version 5.2
LanguageEnglish
  • C#
  • JS

Script language

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

Mesh.colors

Switch to Manual
public Color[] colors;

Description

Vertex colors of the mesh.

If no vertex colors are available an empty array will be returned.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Color[] colors = new Color[vertices.Length]; int i = 0; while (i < vertices.Length) { colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].y); i++; } mesh.colors = colors; } }

For performance reasons, consider using colors32 instead. This will avoid byte-to-float conversions in colors, as well as use less temporary memory.