Version: 2017.1
public void SetTexture (string name, Texture value);
public void SetTexture (int nameID, Texture value);

参数

nameID 属性名称 ID,使用 Shader.PropertyToID 获取。
name 属性名称,例如“_MainTex”。
value 要设置的纹理。

描述

设置指定的纹理。

许多着色器使用多个纹理。使用 SetTexture 可更改纹理(由着色器属性名称或唯一的属性名称 ID 标识)。

When setting textures 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.

Unity 内置着色器使用的常用纹理名称:\ "_MainTex" 是主漫射纹理。它还可以通过 mainTexture 属性进行访问。\ "_BumpMap" 是法线贴图。

另请参阅:mainTexture 属性、GetTextureShader.PropertyToIDProperties in Shader Programs