//得到所有可渲染的子物体Renderer[] rds = transform.GetComponentsInChildren<Renderer>();//逐一遍历他的子物体中的Renderer foreach (Renderer render in rds) { //逐一遍历子物体的子材质(renderer中的material)
foreach (Material material in render.materials) {
var r = material.color.r;
var g = material.color.g;
var b = material.color.b;
material.color = new Color(r, g, b, _Alpha);
}}附加的判断var render = transform.GetComponent<Renderer>();
if (render != null)
{
foreach (Material material in render.materials)
{
var r = material.color.r;
var g = material.color.g;
var b = material.color.b;
material.color = new Color(r, g, b, _Alpha);
}
}
时间: 2024-11-10 18:44:31