public void SetColor (string name, Color value);
public void SetColor (int nameID, Color value);

Parameters

nameID 属性名称 ID,使用 Shader.PropertyToID 获取。
name 属性名称,例如“_Color”。
value 要设置的颜色值。

Description

设置指定的颜色值。

许多着色器使用多种颜色。使用 SetColor 可更改颜色(由着色器属性名称或唯一的属性名称 ID 标识)。

When setting color values on materials using the Standard Shader, you should be aware that you may need to use EnableKeyword to enable features of the shader that were not previously in use. For more detail, read Accessing Materials via Script.

Common color names used by Unity's builtin shaders:
"_Color" is the main color of a material. This can also be accessed via color property.
"_EmissionColor" is the emissive color of a material.

另请参阅:colorGetColorShader.PropertyToIDProperties in Shader Programs

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { Renderer rend = GetComponent<Renderer>(); rend.material.shader = Shader.Find("Specular"); rend.material.SetColor("_SpecColor", Color.red); } }