LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

This version of Unity is unsupported.

Material.SetTexture

Switch to Manual
public method SetTexture(name: string, value: Texture): void;
public method SetTexture(nameID: int, value: Texture): void;

Parameters

nameIDProperty name ID, use Shader.PropertyToID to get it.
nameProperty name, e.g. "_MainTex".
valueTexture to set.

Description

Sets a named texture.

Many shaders use more than one texture. Use SetTexture to change the texture (identified by shader property name, or unique property name 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.

Common texture names used by Unity's builtin shaders:
"_MainTex" is the main diffuse texture. This can also be accessed via mainTexture property.
"_BumpMap" is the normal map.

The shader properties also show some of the keywords needed to set the Texture of a Material. To see this, go to your Material and right click on the Shader dropdown at the top. Next, pick Select Shader.

See Also: mainTexture property, GetTexture, Shader.PropertyToID, Properties in Shader Programs.

no example available in JavaScript