Renderer.material 材质

var material : Material

Description描述

The material of this object.

物体的材质。

Modifying material will change the material for this object only.

修改材质仅改变该物体的材质。

If the material is used by any other renderers, this will clone the shared material and start using it from now on.

如果这材质被用于任意其他渲染器,这将克隆共享材质,并从现在开始开始使用它。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
		renderer.material.color = Color.red;
	}
}
// Set main color to red
//设置主颜色为红色
renderer.material.color = Color.red;

另一个例子:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Material[] materials;
	public float changeInterval = 0.33F;
	void Update() {
		if (materials.Length == 0)
			return;

		int index = Time.time / changeInterval;
		index = index % materials.Length;
		renderer.sharedMaterial = materials[index];
	}
}
// Change renderer's material each changeInterval
// seconds from the material array defined in the inspector.
//从检视面板定义材质数组,每changeInterval秒改变渲染器的材质
var materials : Material[];
var changeInterval = 0.33;

function Update () {
	// do nothing if no materials
	//如果没有材质返回
	if (materials.Length == 0) 
		return;

	// we want this material index now
	//我们现在获得材质的索引
	var index : int = Time.time / changeInterval;
	// take a modulo with materials count so that animation repeats
	//材质数求余,就这样重复动画
	index = index % materials.Length;
	// assign it to the renderer
	//赋给给渲染器
	renderer.sharedMaterial = materials[index];
}
Page last updated: 2010-12-17