Set a texture using a string variable

Hello,

I’m trying to set a texture using a string variable, but I don’t know how to do it.

To explain, my object has a main texture. I’m getting this texture name and add “+ _NRM”. With this variable, I have the texture normal map name as a string. Here, everything’s fine but I don’t know how to access this texture using a string variable.

I’m pretty sure it’s possible but I don’t know how. I try to find a way to convert this string as material, but nothing works. Can someone give me help about how to do that please?

PS: I checked a lot’s of topics, but I don’t want to set an array list in my script will all normal map texture of my data.

Use material.GetTexture(“_BumpMap”); if the texture exists on the material.

Note: You should not use the texture name, but the shader property name.

If you used a non-standard name for your shader property, use that property name.

If you need to load the Resource dynamically, use Resources.Load.

string normalmapName = colormapName + "_NRM";
Texture2D normalmap = Resources.Load<Texture2D>(normalmapName);