How can I get or set textures on a material other than the main texture? (eg, the bump map)

I can't figure what is the name of this component, so I'll try to describe it somehow.

When selecting a mesh in the inspector, there are 2 textures displayed. One texture is accessible trough

Texture2D tex = renderer.material.GetTexture("_MainTex") as Texture2D; 

How can I accesses the other texture?

Thanks.

Different shaders which have multiple textures will have an internal variable name for each texture. As you've shown, the common name for the main diffuse texture is "_MainTex", and some other names used in some of Unity's built in shaders are:

  • "_BumpMap" (the normal map in bumpmapped shaders)
  • "_Cube" (the reflection cubemap in reflective shaders)
  • "_DecalTex" (for the decal shader)
  • "_Detail" (for a shader which allows detail maps)
  • "_ParallaxMap" (for parallax mapped shaders)

You can also access the "_MainTex" more conveniently by using the .mainTexture property of the Material class like this:

Texture2D tex = renderer.material.mainTexture;