Mesh.colors 顶点颜色

var colors : Color[]

Description描述

Returns the vertex colors of the mesh.

返回网格的顶点颜色。

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

如果没有提供

顶点颜色,那么一个空的数组将被返回。
using UnityEngine;

using System.Collections;



public class example : 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;

	}

}
// Sets the vertex color to be red at the y=0 and green at y=1.

// 设置顶点颜色,使y=0的顶点为红色,y=1的顶点为绿色。

// (Note that most builtin shaders don't display vertex colors, 

// (注意大多数的内置渲染器不显示顶点颜色

// you can use eg. a particle shader to see vertex colors)

// 您能使用这个例子,一个粒子渲染器来查看顶点颜色。

function Start () {

	var mesh : Mesh = GetComponentMeshFilter.mesh;

	var vertices : Vector3[] = mesh.vertices;

	var colors : Color[] = new Color[vertices.Length];



	for (var i = 0; i < vertices.Length;i++)

		colors[i] = Color.Lerp(Color.red, Color.green, vertices[i].y);



	mesh.colors = colors;

}
Page last updated: 2010-12-9