Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Mesh.colors

マニュアルに切り替える
public Color[] colors;

説明

メッシュの頂点の色配列

頂点カラーが使用できない場合、空の配列が返されます。

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; } }

パフォーマンス上の理由から、代わりに colors32 を使うことを検討してください。 これは Colors における byte-float 変換をせず、テンポラリーメモリの使用も少ないです。