Material.HasProperty 是否有属性

function HasProperty (propertyName : string) : bool

Description描述

Checks if material's shader has a property of a given name.

检查材质的着色器是否具有给定名称的属性

参见: Materials

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
		if (renderer.material.HasProperty("_Color"))
			renderer.material.SetColor("_Color", Color.red);

	}
}
// Attach this to a gameObject that has a renderer.
//把它附加在有renderer组件的游戏物体(gameobject)上

if(renderer.material.HasProperty("_Color"))
	renderer.material.SetColor("_Color", Color.red );
Page last updated: 2011-1-22